1 | #! /usr/bin/python |
---|
2 | |
---|
3 | """ this file was written by Paul Brossier |
---|
4 | it is released under the GNU/GPL license. |
---|
5 | """ |
---|
6 | |
---|
7 | import sys |
---|
8 | from aubio.task import * |
---|
9 | |
---|
10 | usage = "usage: %s [options] -i soundfile" % sys.argv[0] |
---|
11 | |
---|
12 | def 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") |
---|
18 | parser.add_option("-m","--mode", |
---|
19 | action="store", dest="mode", default='dual', |
---|
20 | help="onset detection mode [default=dual] \ |
---|
21 | complexdomain|hfc|phase|specdiff|energy|kl|mkl|dual") |
---|
22 | parser.add_option("-B","--bufsize", |
---|
23 | action="store", dest="bufsize", default=512, |
---|
24 | help="buffer size [default=512]") |
---|
25 | parser.add_option("-H","--hopsize", |
---|
26 | action="store", dest="hopsize", default=256, |
---|
27 | help="overlap size [default=256]") |
---|
28 | parser.add_option("-t","--threshold", |
---|
29 | action="store", dest="threshold", default=0.650, |
---|
30 | help="onset peak picking threshold [default=0.650]") |
---|
31 | parser.add_option("-C","--dcthreshold", |
---|
32 | action="store", dest="dcthreshold", default=-1., |
---|
33 | help="onset peak picking DC component [default=-1.]") |
---|
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", |
---|
41 | action="store", dest="delay", |
---|
42 | help="number of seconds to take back [default=system]\ |
---|
43 | default system delay is 3*hopsize/samplerate") |
---|
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") |
---|
51 | parser.add_option("-d","--derivate", |
---|
52 | action="store_true", dest="derivate", default=False, |
---|
53 | help="derivate onset detection function") |
---|
54 | parser.add_option("-S","--silencecut", |
---|
55 | action="store_true", dest="silencecut", default=False, |
---|
56 | help="outputs silence locations") |
---|
57 | parser.add_option("-z","--zerocross", |
---|
58 | action="store", dest="zerothres", default=0.008, |
---|
59 | help="zero-crossing threshold for slicing [default=0.00008]") |
---|
60 | # plotting functions |
---|
61 | parser.add_option("-p","--plot", |
---|
62 | action="store_true", dest="plot", default=False, |
---|
63 | help="draw plot") |
---|
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") |
---|
70 | parser.add_option("-O","--outplot", |
---|
71 | action="store", dest="outplot", default=None, |
---|
72 | help="save plot to output.{ps,png}") |
---|
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") |
---|
79 | # to be implemented |
---|
80 | parser.add_option("-b","--beat", |
---|
81 | action="store_true", dest="beat", default=False, |
---|
82 | help="output beat locations") |
---|
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 | |
---|
89 | options, args = parse_args() |
---|
90 | |
---|
91 | filename = options.filename |
---|
92 | params = taskparams() |
---|
93 | params.hopsize = int(options.hopsize) |
---|
94 | params.bufsize = int(options.bufsize) |
---|
95 | params.threshold = float(options.threshold) |
---|
96 | params.dcthreshold = float(options.dcthreshold) |
---|
97 | params.zerothres = float(options.zerothres) |
---|
98 | params.silence = float(options.silence) |
---|
99 | params.mintol = float(options.mintol) |
---|
100 | params.verbose = options.verbose |
---|
101 | # default take back system delay |
---|
102 | if options.delay: params.delay = int(float(options.delay)/params.step) |
---|
103 | |
---|
104 | dotask = taskonset |
---|
105 | if options.beat: |
---|
106 | dotask = taskbeat |
---|
107 | elif options.silencecut: |
---|
108 | dotask = tasksilence |
---|
109 | elif options.plot or options.func: |
---|
110 | params.storefunc=True |
---|
111 | else: |
---|
112 | params.storefunc=False |
---|
113 | |
---|
114 | lonsets, lofunc = [], [] |
---|
115 | wplot,oplots = [],[] |
---|
116 | modes = options.mode.split(',') |
---|
117 | for i in range(len(modes)): |
---|
118 | params.onsetmode = modes[i] |
---|
119 | filetask = dotask(filename,params=params) |
---|
120 | onsets = filetask.compute_all() |
---|
121 | |
---|
122 | #lonsets.append(onsets) |
---|
123 | if not options.silencecut: |
---|
124 | ofunc = filetask.ofunc |
---|
125 | lofunc.append(ofunc) |
---|
126 | |
---|
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 |
---|
132 | |
---|
133 | if options.plot: filetask.plotplot(wplot, oplots, outplot=options.outplot) |
---|
134 | |
---|
135 | if options.cut: |
---|
136 | a = taskcut(filename,onsets,params=params) |
---|
137 | a.compute_all() |
---|