source: python/aubiocut @ 00e4659

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

import 0.1.7.1

  • Property mode set to 100755
File size: 2.1 KB
RevLine 
[96fb8ad]1#!/usr/bin/python
2
3""" this file was written by Paul Brossier
4  it is released under the GNU/GPL license.
5"""
6
7from aubio.aubioclass import *
8import sys
9
10def getonsets(filein,threshold):
11        bufsize   = 1024
12        hopsize   = bufsize/2
13        frameread = 0
14        filei     = sndfile(filein)
15        srate     = filei.samplerate()
16        channels  = filei.channels()
17        myvec     = fvec(hopsize,channels)
18        readsize  = filei.read(hopsize,myvec)
19        opick     = onsetpick(bufsize,hopsize,channels,myvec,threshold)
20        #newname   = "%s%.8f%s" % ("/tmp/",0.0000000,filein[-4:])
21        #fileo     = sndfile(newname,model=filei)
22        mylist    = list()
23        while(readsize==hopsize):
24                readsize = filei.read(hopsize,myvec)
25                isonset,val = opick.do(myvec)
26                if (isonset == 1):
27                    now = (frameread-4)*hopsize/(srate+0.)
28                    #del fileo
29                    #fileo = sndfile("%s%f%s" % ("/tmp/",now,filein[-4:]),model=filei)
30                    mylist.append(now)
31                #writesize = fileo.write(readsize,myoldvec)
32                frameread += 1
33        return mylist
34
35def cutfile(filein,onsets):
36        hopsize   = 512
37        frameread = 0
38        readsize  = hopsize
39        filei     = sndfile(filein)
40        srate     = filei.samplerate()
41        channels  = filei.channels()
42        newname   = "%s%f%s" % ("/tmp/",0.0000000,filein[-4:])
43        fileo     = sndfile(newname,model=filei)
44        myvec     = fvec(hopsize,channels)
45        while(readsize==hopsize):
46                readsize = filei.read(hopsize,myvec)
47                now = (frameread)*hopsize/(srate+0.)
48                writesize = fileo.write(readsize,myvec)
49                if len(onsets) and now == onsets[0]:
50                    onsets.pop(0)
51                    del fileo
52                    fileo = sndfile("%s%f%s%s" % ("/tmp/",now,".",filein.split(".")[-1]),model=filei)
53                frameread += 1
54        del fileo
55
56filename  = sys.argv[1]
57threshold = sys.argv[2]
58onsets    = getonsets(filename,threshold)
59cutfile(filename,onsets)
Note: See TracBrowser for help on using the repository browser.