Changeset 71f98f1
- Timestamp:
- May 23, 2005, 12:40:33 AM (20 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 296c33a
- Parents:
- 2cdae81
- Location:
- python
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/aubio/aubioclass.py
r2cdae81 r71f98f1 55 55 56 56 class onsetdetection: 57 """ class for aubio_onsetdetection """ 57 58 def __init__(self,type,buf,chan): 58 59 self.od = new_aubio_onsetdetection(type,buf,chan) … … 63 64 64 65 class peakpick: 66 """ class for aubio_peakpicker """ 65 67 def __init__(self,threshold=0.1): 66 68 self.pp = new_aubio_peakpicker(threshold) … … 71 73 72 74 class onsetpick: 75 """ superclass for aubio_pvoc + aubio_onsetdetection + aubio_peakpicker """ 73 76 def __init__(self,bufsize,hopsize,channels,myvec,threshold,mode='dual'): 74 77 self.myfft = cvec(bufsize,channels) … … 152 155 return mylist 153 156 154 155 157 def getonsets(filein,threshold=0.2,silence=-70.,bufsize=1024,hopsize=512,mode='dual'): 156 158 frameread = 0 … … 185 187 return mylist 186 188 187 188 189 class pitchpick: 189 190 def __init__(self,bufsize,hopsize,channels,myvec,srate): -
python/aubiocut
r2cdae81 r71f98f1 6 6 7 7 from aubio.aubioclass import * 8 import sys9 8 10 9 bufsize = 1024 11 10 hopsize = bufsize/2 12 11 12 def cutfile(filein,slicetimes,zerothres=0.002): 13 frameread = 0 14 readsize = hopsize 15 filei = sndfile(filein) 16 framestep = hopsize/(filei.samplerate()+0.) 17 channels = filei.channels() 18 newname = "%s%f%s" % ("/tmp/",0.0000000,filein[-4:]) 19 fileo = sndfile(newname,model=filei) 20 myvec = fvec(hopsize,channels) 21 mycopy = fvec(hopsize,channels) 22 while(readsize==hopsize): 23 readsize = filei.read(hopsize,myvec) 24 # write to current file 25 if len(slicetimes) and frameread >= slicetimes[0]: 26 slicetimes.pop(0) 27 # write up to 1st zero crossing 28 zerocross = 0 29 while ( abs( myvec.get(zerocross,0) ) > zerothres ): 30 zerocross += 1 31 writesize = fileo.write(zerocross,myvec) 32 fromcross = 0 33 while (zerocross < readsize): 34 for i in range(channels): 35 mycopy.set(myvec.get(zerocross,i),fromcross,i) 36 fromcross += 1 37 zerocross += 1 38 del fileo 39 fileo = sndfile("%s%s%f%s%s" % 40 (filein.split(".")[0].split("/")[-1],".", 41 frameread*framestep,".",filein.split(".")[-1]),model=filei) 42 writesize = fileo.write(fromcross,mycopy) 43 else: 44 writesize = fileo.write(readsize,myvec) 45 frameread += 1 46 del fileo 13 47 14 def 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 48 import sys 51 49 filename = sys.argv[1] 52 threshold = sys.argv[2] 50 threshold = 0.2 51 if (len(sys.argv) > 2): threshold = sys.argv[2] 53 52 onsets = getonsets(filename,threshold) 54 53 cutfile(filename,onsets)
Note: See TracChangeset
for help on using the changeset viewer.