source: python/aubiocut @ 62c6075

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

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

  • Property mode set to 100755
File size: 1.6 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
13
14def cutfile(filein,onsets):
15        frameread = 0
16        zerothres = 0.002
17        readsize  = hopsize
18        filei     = sndfile(filein)
19        framestep = hopsize/(filei.samplerate()+0.)
20        channels  = filei.channels()
21        newname   = "%s%f%s" % ("/tmp/",0.0000000,filein[-4:])
22        fileo     = sndfile(newname,model=filei)
23        myvec     = fvec(hopsize,channels)
24        mycopy    = fvec(hopsize,channels)
25        while(readsize==hopsize):
26                readsize = filei.read(hopsize,myvec)
27                # write to current file
28                if len(onsets) and frameread >= onsets[0]:
29                    onsets.pop(0)
30                    # write up to 1st zero crossing
31                    zerocross = 0
32                    while ( abs( myvec.get(zerocross,0) ) > zerothres ):
33                        zerocross += 1
34                    writesize = fileo.write(zerocross,myvec)
35                    fromcross = 0
36                    while (zerocross < readsize):
37                        for i in range(channels):
38                                mycopy.set(myvec.get(zerocross,i),fromcross,i)
39                        fromcross += 1
40                        zerocross += 1
41                    del fileo
42                    fileo = sndfile("%s%s%f%s%s" % 
43                        (filein.split(".")[0].split("/")[-1],".",
44                        frameread*framestep,".",filein.split(".")[-1]),model=filei)
45                    writesize = fileo.write(fromcross,mycopy)
46                else:
47                    writesize = fileo.write(readsize,myvec)
48                frameread += 1
49        del fileo
50
51filename  = sys.argv[1]
52threshold = sys.argv[2]
53onsets    = getonsets(filename,threshold)
54cutfile(filename,onsets)
Note: See TracBrowser for help on using the repository browser.