source: python/aubiodiffs-onset @ e7a7794

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

python: finish getting rid of numarray

  • Property mode set to 100755
File size: 2.6 KB
Line 
1#! /usr/bin/python
2
3"""Copyright (C) 2004 Paul Brossier <piem@altern.org>
4
5print aubio.__LICENSE__ for the terms of use
6"""
7__LICENSE__ = """\
8         Copyright (C) 2004 Paul Brossier <piem@altern.org>
9
10         This program is free software; you can redistribute it and/or modify
11         it under the terms of the GNU General Public License as published by
12         the Free Software Foundation; either version 2 of the License, or
13         (at your option) any later version.
14
15         This program is distributed in the hope that it will be useful,
16         but WITHOUT ANY WARRANTY; without even the implied warranty of
17         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18         GNU General Public License for more details.
19
20         You should have received a copy of the GNU General Public License
21         along with this program; if not, write to the Free Software
22         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23"""           
24
25
26__HELP__ = """\
27# required arguments
28 -c targetfilename
29 -o detectfilename
30(both must be text files with 1 time a line expressed in seconds)
31
32# optional arguments
33 -D <delay>     delay in seconds
34 -v             verbose mode
35 -d             debug mode
36
37# output
38results:number of correct detections
39        number of incorrect detections
40        number of doubled detections
41        number of total detections
42        number of total targets
43
44# example:
45$ aubioonset-comp -c checked-onsets.txt -o handlab-onsets.txt -v
46( gd fp dd ) tot / real
47( 5 4 0 ) 9 / 9
4855.5555555556 %GD       44.4444444444 %FP       0.0 %OD
49
50# bugs
51does not scale to very long lists
52"""
53
54import sys
55from aubio.onsetcompare import onset_diffs
56from aubio.txtfile import read_datafile
57
58# default values
59fileo=None;filec=None;vmode=None;dmode=None;delay=0.
60# default tolerance is 50 ms
61#tol = 0.050
62tol = 0.048
63
64while len(sys.argv) >=2:
65    option = sys.argv[1]; del sys.argv[1]
66    if option == '-h': print __HELP__; sys.exit()
67    if option == '-o': fileo = sys.argv[1]; del sys.argv[1]
68    if option == '-c': filec = sys.argv[1]; del sys.argv[1]
69    if option == '-v': vmode = 'verbose'
70    if option == '-d': dmode = 'debug'
71    if option == '-D': delay = float(sys.argv[1]); del sys.argv[1]
72    if option == '-tol': tol = float(sys.argv[1]); del sys.argv[1]
73
74# arguments required
75if (not fileo) or (not filec):
76    print 'wrong set of arguments. use \'-h\' for help'
77    sys.exit('error: needs at least \'-c targets.txt -o detected.txt\'')
78
79# load files
80ltru, lres = read_datafile(fileo,depth=0),read_datafile(filec,depth=0)
81
82# delay onsets as required with -D
83if delay:
84    for i in range(len(lres)):
85        lres[i] = lres[i] + delay
86# compute errors types
87l = onset_diffs(ltru,lres,tol)
88# print with 1ms precision
89for i in l: print "%.3f" % float(i)
90
Note: See TracBrowser for help on using the repository browser.