shithub: aubio

ref: 0b530cbf3b532383ea84be81b610c7ff41f4d474
dir: /python/aubioonset/

View raw version
#! /usr/bin/python

import sys
import numarray
from aubio.aubioclass import *

usage = "usage: %s [options] soundfile" % sys.argv[0]

def parse_args():
        from optparse import OptionParser
        parser = OptionParser(usage=usage)
        parser.add_option("-v","--verbose",
                          action="store_true", dest="verbose", default=False,
                          help="make lots of noise")
        parser.add_option("-q","--quiet",
                          action="store_false", dest="verbose", default=True, 
                          help="be quiet [default]")
        parser.add_option("-t","--threshold",
                          action="store", dest="threshold", default=0.3, 
                          help="onset detection threshold [default=0.3]")
        parser.add_option("-s","--silence",
                          action="store", dest="silence", default=-70, 
                          help="silence [default=-70]")
        def check_mode(option, opt, value, parser):
                nvalue = parser.rargs[0]
                if   nvalue == 'complexdomain' : setattr(parser.values, option.dest, complexdomain)
                elif nvalue == 'hfc'           : setattr(parser.values, option.dest, hfc)
                elif nvalue == 'phase'         : setattr(parser.values, option.dest, phase)
                elif nvalue == 'specdiff'      : setattr(parser.values, option.dest, specdiff)
                elif nvalue == 'energy'        : setattr(parser.values, option.dest, energy)
                elif nvalue == 'dual'          : setattr(parser.values, option.dest, 'dual')
        parser.add_option("-m","--mode",
                          action="callback", callback=check_mode, dest="mode", default='dual', 
                          help="onsetdetection mode [default=dual]")
        parser.add_option("-o","--outplot",
                          action="store", dest="outplot", default=None, 
                          help="be quiet [default=None]")
        (options, args) = parser.parse_args()
        if not len(args): 
                 print "no file name given\n", usage
                 sys.exit(1)
        return options, args

options, args = parse_args()

filename  = args[0] 
threshold = float(options.threshold)
silence   = float(options.silence)

#onsets = getonsets(filename,threshold,silence,mode=options.mode)
onsets = getonsetscausal(filename,threshold,silence,mode=options.mode)
for i in onsets: print i*512./44100.