Changeset 98df9f4 for python/aubio
- Timestamp:
- May 28, 2005, 11:06:33 PM (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:
- 6b384f3
- Parents:
- ead2920
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/aubio/aubioclass.py
read2920 r98df9f4 96 96 return self.pp.do(self.myonset),self.myonset.get(0,0) 97 97 98 def getonsetsfunc(filein,threshold,silence,bufsize=1024,hopsize=512,mode='dual'): 99 #bufsize = 1024 100 #hopsize = bufsize/2 98 def getonsets(filein,threshold=0.2,silence=-70.,bufsize=1024,hopsize=512,mode='dual',localmin=False,storefunc=False): 101 99 frameread = 0 102 100 filei = sndfile(filein) … … 106 104 opick = onsetpick(bufsize,hopsize,channels,myvec,threshold,mode=mode) 107 105 mylist = list() 108 #ovalist = [0., 0., 0., 0., 0., 0.] 109 ovalist = [0., 0., 0., 0., 0.] 110 ofunclist = [] 106 if localmin: 107 ovalist = [0., 0., 0., 0., 0.] 108 if storefunc: 109 ofunclist = [] 111 110 while(readsize): 112 111 readsize = filei.read(hopsize,myvec) … … 114 113 if (aubio_silence_detection(myvec(),silence)): 115 114 isonset=0 116 ovalist.append(val) 117 ovalist.pop(0) 118 ofunclist.append(val) 115 if localmin: 116 ovalist.append(val) 117 ovalist.pop(0) 118 if storefunc: 119 ofunclist.append(val) 119 120 if (isonset == 1): 120 i=len(ovalist)-1 121 # find local minima before peak 122 while ovalist[i-1] < ovalist[i] and i > 0: 123 i -= 1 124 now = (frameread+1-i) 121 if localmin: 122 i=len(ovalist)-1 123 # find local minima before peak 124 while ovalist[i-1] < ovalist[i] and i > 0: 125 i -= 1 126 now = (frameread+1-i) 127 else: 128 now = frameread 125 129 if now > 0 : 126 130 mylist.append(now) … … 129 133 mylist.append(now) 130 134 frameread += 1 131 return mylist, ofunclist 135 if storefunc: return mylist, ofunclist 136 else: return mylist 132 137 138 def cutfile(filein,slicetimes,zerothres=0.002,bufsize=1024,hopsize=512): 139 frameread = 0 140 readsize = hopsize 141 filei = sndfile(filein) 142 framestep = hopsize/(filei.samplerate()+0.) 143 channels = filei.channels() 144 newname = "%s%f%s" % ("/tmp/",0.0000000,filein[-4:]) 145 fileo = sndfile(newname,model=filei) 146 myvec = fvec(hopsize,channels) 147 mycopy = fvec(hopsize,channels) 148 while(readsize==hopsize): 149 readsize = filei.read(hopsize,myvec) 150 # write to current file 151 if len(slicetimes) and frameread >= slicetimes[0]: 152 slicetimes.pop(0) 153 # write up to 1st zero crossing 154 zerocross = 0 155 while ( abs( myvec.get(zerocross,0) ) > zerothres ): 156 zerocross += 1 157 writesize = fileo.write(zerocross,myvec) 158 fromcross = 0 159 while (zerocross < readsize): 160 for i in range(channels): 161 mycopy.set(myvec.get(zerocross,i),fromcross,i) 162 fromcross += 1 163 zerocross += 1 164 del fileo 165 fileo = sndfile("%s%s%f%s%s" % 166 (filein.split(".")[0].split("/")[-1],".", 167 frameread*framestep,".",filein.split(".")[-1]),model=filei) 168 writesize = fileo.write(fromcross,mycopy) 169 else: 170 writesize = fileo.write(readsize,myvec) 171 frameread += 1 172 del fileo 133 173 134 def getonsetscausal(filein,threshold,silence,bufsize=1024,hopsize=512,mode='dual'):135 frameread = 0136 filei = sndfile(filein)137 channels = filei.channels()138 myvec = fvec(hopsize,channels)139 readsize = filei.read(hopsize,myvec)140 opick = onsetpick(bufsize,hopsize,channels,myvec,threshold,mode=mode)141 mylist = list()142 while(readsize):143 readsize = filei.read(hopsize,myvec)144 isonset,val = opick.do(myvec)145 if (aubio_silence_detection(myvec(),silence)):146 isonset=0147 if (isonset == 1):148 now = frameread149 if now > 0 :150 mylist.append(now)151 else:152 now = 0153 mylist.append(now)154 frameread += 1155 return mylist156 157 def getonsets(filein,threshold=0.2,silence=-70.,bufsize=1024,hopsize=512,mode='dual'):158 frameread = 0159 filei = sndfile(filein)160 channels = filei.channels()161 samplerate= filei.samplerate()162 myvec = fvec(hopsize,channels)163 readsize = filei.read(hopsize,myvec)164 opick = onsetpick(bufsize,hopsize,channels,myvec,threshold,mode=mode)165 mylist = list()166 #ovalist = [0., 0., 0., 0., 0., 0.]167 ovalist = [0., 0., 0., 0., 0.]168 while(readsize):169 readsize = filei.read(hopsize,myvec)170 isonset,val = opick.do(myvec)171 if (aubio_silence_detection(myvec(),silence)):172 isonset=0173 ovalist.append(val)174 ovalist.pop(0)175 if (isonset == 1):176 i=len(ovalist)-1177 # find local minima before peak178 while ovalist[i-1] < ovalist[i] and i > 0:179 i -= 1180 now = (frameread+1-i)181 if now > 0 :182 mylist.append(now)183 else:184 now = 0185 mylist.append(now)186 frameread += 1187 return mylist188 174 189 175 class pitchpick:
Note: See TracChangeset
for help on using the changeset viewer.