1 | #! /usr/bin/python |
---|
2 | |
---|
3 | import sys |
---|
4 | import numarray |
---|
5 | from aubio.aubioclass import * |
---|
6 | |
---|
7 | usage = "usage: %s [options] soundfile" % sys.argv[0] |
---|
8 | |
---|
9 | def check_mode(option, opt, value, parser): |
---|
10 | nvalue = parser.rargs[0] |
---|
11 | if nvalue == 'complexdomain' : |
---|
12 | setattr(parser.values, option.dest, complexdomain) |
---|
13 | elif nvalue == 'hfc' : |
---|
14 | setattr(parser.values, option.dest, hfc) |
---|
15 | elif nvalue == 'phase' : |
---|
16 | setattr(parser.values, option.dest, phase) |
---|
17 | elif nvalue == 'specdiff' : |
---|
18 | setattr(parser.values, option.dest, specdiff) |
---|
19 | elif nvalue == 'energy' : |
---|
20 | setattr(parser.values, option.dest, energy) |
---|
21 | elif nvalue == 'dual' : |
---|
22 | setattr(parser.values, option.dest, 'dual') |
---|
23 | |
---|
24 | def parse_args(): |
---|
25 | from optparse import OptionParser |
---|
26 | parser = OptionParser(usage=usage) |
---|
27 | parser.add_option("-m","--mode", action="callback", |
---|
28 | callback=check_mode, dest="mode", default='dual', |
---|
29 | help="onsetdetection mode [default=dual] \ |
---|
30 | complexdomain|hfc|phase|specdiff|energy|dual") |
---|
31 | parser.add_option("-o","--outplot", |
---|
32 | action="store", dest="outplot", default=None, |
---|
33 | help="be quiet [default=None]") |
---|
34 | parser.add_option("-t","--threshold", |
---|
35 | action="store", dest="threshold", default=0.3, |
---|
36 | help="onset detection threshold [default=0.3]") |
---|
37 | parser.add_option("-s","--silence", |
---|
38 | action="store", dest="silence", default=-70, |
---|
39 | help="silence [default=-70]") |
---|
40 | parser.add_option("-M","--mintol", |
---|
41 | action="store", dest="mintol", default=0.048, |
---|
42 | help="minimum inter onset interval [default=0.048]") |
---|
43 | parser.add_option("-v","--verbose", |
---|
44 | action="store_true", dest="verbose", default=False, |
---|
45 | help="make lots of noise") |
---|
46 | parser.add_option("-q","--quiet", |
---|
47 | action="store_false", dest="verbose", default=True, |
---|
48 | help="be quiet [default]") |
---|
49 | (options, args) = parser.parse_args() |
---|
50 | if not len(args): |
---|
51 | print "no file name given\n", usage |
---|
52 | sys.exit(1) |
---|
53 | return options, args |
---|
54 | |
---|
55 | options, args = parse_args() |
---|
56 | |
---|
57 | filename = args[0] |
---|
58 | threshold = float(options.threshold) |
---|
59 | silence = float(options.silence) |
---|
60 | |
---|
61 | #onsets = getonsets(filename,threshold,silence,mode=options.mode) |
---|
62 | onsets = getonsetscausal(filename,threshold,silence,mode=options.mode) |
---|
63 | |
---|
64 | # print all |
---|
65 | #for i in onsets: print i*512./44100. |
---|
66 | # prune doubled |
---|
67 | last = -10. |
---|
68 | mintol = float(options.mintol) |
---|
69 | for i in onsets: |
---|
70 | new = i*512./44100. |
---|
71 | if (new - last > mintol): print "%f" % new |
---|
72 | last = new |
---|