source: python/aubiocut @ e83c895

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

splitting up tasks in many files
splitting up tasks in many files

  • Property mode set to 100755
File size: 5.8 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",
[2d04b86]29                          action="store", dest="threshold", default=0.650,
30                          help="onset peak picking threshold [default=0.650]")
[83ff0ab]31        parser.add_option("-C","--dcthreshold",
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")
[83ff0ab]64        parser.add_option("-f","--function",
65                          action="store_true", dest="func", default=False,
66                          help="print detection function")
67        parser.add_option("-n","--no-onsets",
68                          action="store_true", dest="nplot", default=False,
69                          help="plot only detection functions")
[80c0417]70        parser.add_option("-O","--outplot",
71                          action="store", dest="outplot", default=None,
72                          help="save plot to output.{ps,png}")
[98df9f4]73        parser.add_option("-v","--verbose",
74                          action="store_true", dest="verbose", default=False,
75                          help="make lots of noise [default]")
76        parser.add_option("-q","--quiet",
77                          action="store_false", dest="verbose", default=False,
78                          help="be quiet")
[427be71]79        # to be implemented
80        parser.add_option("-b","--beat",
81                          action="store_true", dest="beat", default=False,
[d9101a5]82                          help="output beat locations")
[98df9f4]83        (options, args) = parser.parse_args()
84        if not options.filename:
85                 print "no file name given\n", usage
86                 sys.exit(1)
87        return options, args
88
89options, args = parse_args()
90
91filename   = options.filename
[4f4a8a4]92params = taskparams()
93params.hopsize    = int(options.hopsize)
94params.bufsize    = int(options.bufsize)
95params.threshold  = float(options.threshold)
[83ff0ab]96params.dcthreshold = float(options.dcthreshold)
[4f4a8a4]97params.zerothres  = float(options.zerothres)
98params.silence    = float(options.silence)
99params.mintol     = float(options.mintol)
[83ff0ab]100params.verbose    = options.verbose
[80c0417]101# default take back system delay
[83ff0ab]102if options.delay: params.delay = int(float(options.delay)/params.step)
[98df9f4]103
[83ff0ab]104dotask = taskonset
105if options.beat:
106        dotask = taskbeat
107elif options.silencecut:
108        dotask = tasksilence
109elif options.plot or options.func:
110        params.storefunc=True
111else:             
112        params.storefunc=False
[5e491b3b]113
114lonsets, lofunc = [], []
[83ff0ab]115wplot,oplots = [],[]
[4f4a8a4]116modes = options.mode.split(',')
117for i in range(len(modes)):
118        params.onsetmode = modes[i]
[ada5baf]119        filetask = dotask(filename,params=params)
[4f4a8a4]120        onsets = filetask.compute_all()
[5e491b3b]121
[83ff0ab]122        #lonsets.append(onsets)
[79c04d8]123        if not options.silencecut:
[83ff0ab]124                ofunc = filetask.ofunc
[79c04d8]125                lofunc.append(ofunc)
[98df9f4]126
[83ff0ab]127        if options.plot: filetask.plot(onsets, ofunc, wplot, oplots, nplot=options.nplot)
128
129        if options.func:
130                for i in ofunc:
131                        print i
[98df9f4]132
[83ff0ab]133if options.plot: filetask.plotplot(wplot, oplots, outplot=options.outplot)
[80c0417]134
[98df9f4]135if options.cut:
[4f4a8a4]136        a = taskcut(filename,onsets,params=params)
137        a.compute_all()
Note: See TracBrowser for help on using the repository browser.