shithub: aubio

ref: e997b1af642cbc14d067302f897f90d740571bf2
dir: /python/aubioonset/

View raw version
#!/usr/bin/python

def do(filein,threshold):
        import aubio.aubioclass as aubio
        hopsize   = 512
        bufsize   = 1024
        frameread = 0
        filei     = aubio.sndfile(filein)
        srate     = filei.samplerate()
        channels  = filei.channels() 
        myvec     = aubio.fvec(hopsize,channels)
        readsize  = filei.read(hopsize,myvec)
        opick     = aubio.onsetpick(bufsize,hopsize,channels,myvec,threshold)
        mylist    = list()
        while(readsize==hopsize):
                readsize = filei.read(hopsize,myvec)
                isonset,val = opick.do(myvec) 
                if (isonset == 1):
                    now = (frameread-3)*hopsize/(srate+0.)
                    print "%.8f\t%.2f"% (now,val)
                frameread += 1

if __name__ == "__main__":
        import sys
        do(sys.argv[1],sys.argv[2])