Changeset 19b56b0 for python/aubioonset


Ignore:
Timestamp:
Mar 29, 2005, 5:51:44 PM (19 years ago)
Author:
Paul Brossier <piem@altern.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
9499a546
Parents:
7445aea
Message:

updated python/aubio/aubioclass.py and python/aubiocut

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/aubioonset

    r7445aea r19b56b0  
    1 #!/usr/bin/python
     1#! /usr/bin/python
    22
    3 def do(filein,threshold):
    4         import aubio.aubioclass as aubio
    5         hopsize   = 512
    6         bufsize   = 1024
    7         frameread = 0
    8         filei     = aubio.sndfile(filein)
    9         srate     = filei.samplerate()
    10         channels  = filei.channels()
    11         myvec     = aubio.fvec(hopsize,channels)
    12         readsize  = filei.read(hopsize,myvec)
    13         opick     = aubio.onsetpick(bufsize,hopsize,channels,myvec,threshold)
    14         mylist    = list()
    15         while(readsize==hopsize):
    16                 readsize = filei.read(hopsize,myvec)
    17                 isonset,val = opick.do(myvec)
    18                 if (isonset == 1):
    19                     now = (frameread-3)*hopsize/(srate+0.)
    20                     print "%.8f\t%.2f"% (now,val)
    21                 frameread += 1
     3import sys
     4import numarray
     5from aubio.aubioclass import *
    226
    23 if __name__ == "__main__":
    24         import sys
    25         do(sys.argv[1],sys.argv[2])
     7usage = "usage: %s [options] soundfile" % sys.argv[0]
     8
     9def 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        (options, args) = parser.parse_args()
     39        if not len(args):
     40                 print "no file name given\n", usage
     41                 sys.exit(1)
     42        return options, args
     43
     44options, args = parse_args()
     45
     46filename  = args[0]
     47threshold = float(options.threshold)
     48silence   = float(options.silence)
     49
     50#onsets = getonsets(filename,threshold,silence,mode=options.mode)
     51onsets = getonsetscausal(filename,threshold,silence,mode=options.mode)
     52for i in onsets: print i*512./44100.
Note: See TracChangeset for help on using the changeset viewer.