source: python/aubiocut @ 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: 6.6 KB
RevLine 
[98df9f4]1#! /usr/bin/python
[96fb8ad]2
3""" this file was written by Paul Brossier
4  it is released under the GNU/GPL license.
5"""
6
[98df9f4]7import sys
[13c3fba]8from aubio.task import *
[96fb8ad]9
[98df9f4]10usage = "usage: %s [options] -i soundfile" % sys.argv[0]
[96fb8ad]11
[98df9f4]12def parse_args():
13        from optparse import OptionParser
14        parser = OptionParser(usage=usage)
15        parser.add_option("-i","--input",
16                          action="store", dest="filename",
17                          help="input sound file")
[4f4a8a4]18        parser.add_option("-m","--mode",
[ada5baf]19                          action="store", dest="mode", default='dual',
[80c0417]20                          help="onset detection mode [default=dual] \
[2d04b86]21                          complexdomain|hfc|phase|specdiff|energy|kl|mkl|dual")
[98df9f4]22        parser.add_option("-B","--bufsize",
[855ed0a]23                          action="store", dest="bufsize", default=512,
[61680aa]24                          help="buffer size [default=512]")
[98df9f4]25        parser.add_option("-H","--hopsize",
[2d04b86]26                          action="store", dest="hopsize", default=256,
27                          help="overlap size [default=256]")
[98df9f4]28        parser.add_option("-t","--threshold",
[6e35163]29                          action="store", dest="threshold", default=0.3,
30                          help="onset peak picking threshold [default=0.3]")
[83ff0ab]31        parser.add_option("-C","--dcthreshold",
[9bf3831]32                          action="store", dest="dcthreshold", default=1.,
33                          help="onset peak picking DC component [default=1.]")
[98df9f4]34        parser.add_option("-s","--silence",
35                          action="store", dest="silence", default=-70,
36                          help="silence threshold [default=-70]")
37        parser.add_option("-M","--mintol",
38                          action="store", dest="mintol", default=0.048,
39                          help="minimum inter onset interval [default=0.048]")
40        parser.add_option("-D","--delay",
[80c0417]41                          action="store", dest="delay", 
42                          help="number of seconds to take back [default=system]\
[855ed0a]43                          default system delay is 3*hopsize/samplerate")
[98df9f4]44        parser.add_option("-L","--localmin",
45                          action="store_true", dest="localmin", default=False,
46                          help="use local minima after peak detection")
47        parser.add_option("-c","--cut",
48                          action="store_true", dest="cut", default=False,
49                          help="cut input sound file at detected labels \
50                          best used with option -L")
[80c0417]51        parser.add_option("-d","--derivate",
52                          action="store_true", dest="derivate", default=False,
53                          help="derivate onset detection function")
[13340a68]54        parser.add_option("-S","--silencecut",
55                          action="store_true", dest="silencecut", default=False,
56                          help="outputs silence locations")
[98df9f4]57        parser.add_option("-z","--zerocross",
[427be71]58                          action="store", dest="zerothres", default=0.008,
[855ed0a]59                          help="zero-crossing threshold for slicing [default=0.00008]")
[80c0417]60        # plotting functions
61        parser.add_option("-p","--plot",
62                          action="store_true", dest="plot", default=False,
63                          help="draw plot")
[9b138a8]64        parser.add_option("-x","--xsize",
65                          action="store", dest="xsize", default=1.,
66                          type='float', help="define xsize for plot")
67        parser.add_option("-y","--ysize",
68                          action="store", dest="ysize", default=1.,
69                          type='float', help="define ysize for plot")
70        parser.add_option("-f","--function",
71                          action="store_true", dest="func", default=False,
72                          help="print detection function")
[83ff0ab]73        parser.add_option("-n","--no-onsets",
74                          action="store_true", dest="nplot", default=False,
[9b138a8]75                          help="do not plot detected onsets")
[80c0417]76        parser.add_option("-O","--outplot",
77                          action="store", dest="outplot", default=None,
78                          help="save plot to output.{ps,png}")
[9b138a8]79        parser.add_option("-F","--spectrogram",
80                          action="store_true", dest="spectro", default=False,
81                          help="add spectrogram to the plot")
[98df9f4]82        parser.add_option("-v","--verbose",
[1566886]83                          action="store_true", dest="verbose", default=True,
[98df9f4]84                          help="make lots of noise [default]")
85        parser.add_option("-q","--quiet",
[1566886]86                          action="store_false", dest="verbose", default=True,
[98df9f4]87                          help="be quiet")
[427be71]88        # to be implemented
89        parser.add_option("-b","--beat",
90                          action="store_true", dest="beat", default=False,
[d9101a5]91                          help="output beat locations")
[98df9f4]92        (options, args) = parser.parse_args()
93        if not options.filename:
94                 print "no file name given\n", usage
95                 sys.exit(1)
96        return options, args
97
98options, args = parse_args()
99
100filename   = options.filename
[4f4a8a4]101params = taskparams()
102params.hopsize    = int(options.hopsize)
103params.bufsize    = int(options.bufsize)
104params.threshold  = float(options.threshold)
[83ff0ab]105params.dcthreshold = float(options.dcthreshold)
[4f4a8a4]106params.zerothres  = float(options.zerothres)
107params.silence    = float(options.silence)
108params.mintol     = float(options.mintol)
[83ff0ab]109params.verbose    = options.verbose
[80c0417]110# default take back system delay
[83ff0ab]111if options.delay: params.delay = int(float(options.delay)/params.step)
[98df9f4]112
[83ff0ab]113dotask = taskonset
114if options.beat:
115        dotask = taskbeat
116elif options.silencecut:
117        dotask = tasksilence
118elif options.plot or options.func:
119        params.storefunc=True
120else:             
121        params.storefunc=False
[5e491b3b]122
123lonsets, lofunc = [], []
[83ff0ab]124wplot,oplots = [],[]
[4f4a8a4]125modes = options.mode.split(',')
126for i in range(len(modes)):
127        params.onsetmode = modes[i]
[ada5baf]128        filetask = dotask(filename,params=params)
[4f4a8a4]129        onsets = filetask.compute_all()
[5e491b3b]130
[83ff0ab]131        #lonsets.append(onsets)
[79c04d8]132        if not options.silencecut:
[83ff0ab]133                ofunc = filetask.ofunc
[79c04d8]134                lofunc.append(ofunc)
[98df9f4]135
[14aae81]136        if options.plot:
137                if options.beat:
138                        filetask.plot(oplots, onsets)
139                else:
140                        filetask.plot(onsets, ofunc, wplot, oplots, nplot=options.nplot)
[83ff0ab]141
142        if options.func:
143                for i in ofunc:
144                        print i
[98df9f4]145
[9b138a8]146if options.outplot:
147  extension = options.outplot.split('.')[-1]
148  outplot = '.'.join(options.outplot.split('.')[:-1])
149else:
150  extension,outplot = None,None
151if options.plot: filetask.plotplot(wplot, oplots, outplot=outplot, extension=extension,
152  xsize=options.xsize,ysize=options.ysize,spectro=options.spectro)
[80c0417]153
[98df9f4]154if options.cut:
[4f4a8a4]155        a = taskcut(filename,onsets,params=params)
156        a.compute_all()
Note: See TracBrowser for help on using the repository browser.