source: python/aubiocut @ b073447

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

updated aubiocut
aubiocut now seeks local minima before the peak, to cut at the beginning of the
attack rather than at an arbitrary three frames ahead of the peak.

  • Property mode set to 100755
File size: 2.2 KB
Line 
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
10bufsize   = 1024
11hopsize   = bufsize/2
12
13def getonsets(filein,threshold):
14        frameread = 0
15        filei     = sndfile(filein)
16        srate     = filei.samplerate()
17        channels  = filei.channels()
18        myvec     = fvec(hopsize,channels)
19        readsize  = filei.read(hopsize,myvec)
20        opick     = onsetpick(bufsize,hopsize,channels,myvec,threshold)
21        #newname   = "%s%.8f%s" % ("/tmp/",0.0000000,filein[-4:])
22        #fileo     = sndfile(newname,model=filei)
23        mylist    = list()
24        ovalist   = [0., 0., 0., 0., 0., 0.]
25        while(readsize==hopsize):
26                readsize = filei.read(hopsize,myvec)
27                isonset,val = opick.do(myvec)
28                ovalist.append(val)
29                ovalist.pop(0)
30                if (isonset == 1):
31                        print frameread
32                        i=len(ovalist)-1
33                        # find local minima
34                        while ovalist[i-1] < ovalist[i] and i > 0:
35                                i -= 1
36                        now = (frameread-i+1)*hopsize/(srate+0.)
37                        #del fileo
38                        #fileo = sndfile("%s%f%s" % ("/tmp/",now,filein[-4:]),model=filei)
39                        mylist.append(now)
40                #writesize = fileo.write(readsize,myoldvec)
41                frameread += 1
42        return mylist
43
44def cutfile(filein,onsets):
45        frameread = 0
46        readsize  = hopsize
47        filei     = sndfile(filein)
48        srate     = filei.samplerate()
49        channels  = filei.channels()
50        newname   = "%s%f%s" % ("/tmp/",0.0000000,filein[-4:])
51        fileo     = sndfile(newname,model=filei)
52        myvec     = fvec(hopsize,channels)
53        while(readsize==hopsize):
54                readsize = filei.read(hopsize,myvec)
55                now = (frameread)*hopsize/(srate+0.)
56                writesize = fileo.write(readsize,myvec)
57                if len(onsets) and now == onsets[0]:
58                    onsets.pop(0)
59                    del fileo
60                    fileo = sndfile("%s%f%s%s" % ("/tmp/",now,".",filein.split(".")[-1]),model=filei)
61                frameread += 1
62        del fileo
63
64filename  = sys.argv[1]
65threshold = sys.argv[2]
66onsets    = getonsets(filename,threshold)
67cutfile(filename,onsets)
Note: See TracBrowser for help on using the repository browser.