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