source: python/aubiocut @ 9cf2833

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 9cf2833 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
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
[e997b1a]10bufsize   = 1024
[65f1edc]11hopsize   = bufsize/2
12
[96fb8ad]13
14def cutfile(filein,onsets):
15        frameread = 0
[19b56b0]16        zerothres = 0.002
[96fb8ad]17        readsize  = hopsize
18        filei     = sndfile(filein)
[19b56b0]19        framestep = hopsize/(filei.samplerate()+0.)
[96fb8ad]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)
[c0ec39c]24        mycopy    = fvec(hopsize,channels)
[96fb8ad]25        while(readsize==hopsize):
26                readsize = filei.read(hopsize,myvec)
[c0ec39c]27                # write to current file
[19b56b0]28                if len(onsets) and frameread >= onsets[0]:
[96fb8ad]29                    onsets.pop(0)
[c0ec39c]30                    # write up to 1st zero crossing
31                    zerocross = 0
[19b56b0]32                    while ( abs( myvec.get(zerocross,0) ) > zerothres ):
[c0ec39c]33                        zerocross += 1
34                    writesize = fileo.write(zerocross,myvec)
35                    fromcross = 0
36                    while (zerocross < readsize):
[77494e7]37                        for i in range(channels):
38                                mycopy.set(myvec.get(zerocross,i),fromcross,i)
[c0ec39c]39                        fromcross += 1
40                        zerocross += 1
[96fb8ad]41                    del fileo
[c0ec39c]42                    fileo = sndfile("%s%s%f%s%s" % 
[19b56b0]43                        (filein.split(".")[0].split("/")[-1],".",
44                        frameread*framestep,".",filein.split(".")[-1]),model=filei)
[c0ec39c]45                    writesize = fileo.write(fromcross,mycopy)
46                else:
47                    writesize = fileo.write(readsize,myvec)
[96fb8ad]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.