shithub: aubio

ref: 8122e54ad1a17377db3662878d2f5ff515d15201
dir: /python.old/aubiodiffs-onset/

View raw version
#! /usr/bin/python

__LICENSE__ = """\
  Copyright (C) 2004-2009 Paul Brossier <piem@aubio.org>

  This file is part of aubio.

  aubio is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  aubio is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
"""            

__HELP__ = """\
# required arguments
 -c targetfilename 
 -o detectfilename 
(both must be text files with 1 time a line expressed in seconds)

# optional arguments
 -D <delay>  	delay in seconds
 -v 		verbose mode
 -d 		debug mode

# output 
results:number of correct detections
        number of incorrect detections
        number of doubled detections
        number of total detections
        number of total targets

# example:
$ aubioonset-comp -c checked-onsets.txt -o handlab-onsets.txt -v
( gd fp dd ) tot / real
( 5 4 0 ) 9 / 9
55.5555555556 %GD       44.4444444444 %FP       0.0 %OD

# bugs
does not scale to very long lists
"""

import sys
from aubio.onsetcompare import onset_diffs
from aubio.txtfile import read_datafile

# default values
fileo=None;filec=None;vmode=None;dmode=None;delay=0.
# default tolerance is 50 ms
#tol = 0.050
tol = 0.048

while len(sys.argv) >=2:
    option = sys.argv[1]; del sys.argv[1]
    if option == '-h': print __HELP__; sys.exit()
    if option == '-o': fileo = sys.argv[1]; del sys.argv[1]
    if option == '-c': filec = sys.argv[1]; del sys.argv[1]
    if option == '-v': vmode = 'verbose'
    if option == '-d': dmode = 'debug'
    if option == '-D': delay = float(sys.argv[1]); del sys.argv[1] 
    if option == '-tol': tol = float(sys.argv[1]); del sys.argv[1] 

# arguments required
if (not fileo) or (not filec):
    print 'wrong set of arguments. use \'-h\' for help' 
    sys.exit('error: needs at least \'-c targets.txt -o detected.txt\'')

# load files
ltru, lres = read_datafile(fileo,depth=0),read_datafile(filec,depth=0)

# delay onsets as required with -D
if delay:
    for i in range(len(lres)):
        lres[i] = lres[i] + delay
# compute errors types
l = onset_diffs(ltru,lres,tol)
# print with 1ms precision
for i in l: print "%.3f" % float(i)