Changeset 19b56b0 for python/aubio
- Timestamp:
- Mar 29, 2005, 5:51:44 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:
- 9499a546
- Parents:
- 7445aea
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/aubio/aubioclass.py
r7445aea r19b56b0 71 71 72 72 class onsetpick: 73 def __init__(self,bufsize,hopsize,channels,myvec,threshold ):73 def __init__(self,bufsize,hopsize,channels,myvec,threshold,mode='dual'): 74 74 self.myfft = cvec(bufsize,channels) 75 75 self.pv = pvoc(bufsize,hopsize,channels) 76 self.myod = onsetdetection(hfc,bufsize,channels) 77 self.myod2 = onsetdetection(complexdomain,bufsize,channels) 78 self.myonset = fvec(1,channels) 79 self.myonset2 = fvec(1,channels) 76 if mode in [complexdomain,hfc,phase,energy,specdiff] : 77 self.myod = onsetdetection(mode,bufsize,channels) 78 self.myonset = fvec(1,channels) 79 else: 80 self.myod = onsetdetection(hfc,bufsize,channels) 81 self.myod2 = onsetdetection(complexdomain,bufsize,channels) 82 self.myonset = fvec(1,channels) 83 self.myonset2 = fvec(1,channels) 84 self.mode = mode 80 85 self.pp = peakpick(float(threshold)) 81 86 … … 83 88 self.pv.do(myvec,self.myfft) 84 89 self.myod.do(self.myfft,self.myonset) 85 self.myod2.do(self.myfft,self.myonset2) 86 self.myonset.set(self.myonset.get(0,0)*self.myonset2.get(0,0),0,0) 90 if self.mode == 'dual': 91 self.myod2.do(self.myfft,self.myonset2) 92 self.myonset.set(self.myonset.get(0,0)*self.myonset2.get(0,0),0,0) 87 93 return self.pp.do(self.myonset),self.myonset.get(0,0) 94 95 def getonsetsfunc(filein,threshold,silence,bufsize=1024,hopsize=512,mode='dual'): 96 #bufsize = 1024 97 #hopsize = bufsize/2 98 frameread = 0 99 filei = sndfile(filein) 100 channels = filei.channels() 101 myvec = fvec(hopsize,channels) 102 readsize = filei.read(hopsize,myvec) 103 opick = onsetpick(bufsize,hopsize,channels,myvec,threshold,mode=mode) 104 mylist = list() 105 #ovalist = [0., 0., 0., 0., 0., 0.] 106 ovalist = [0., 0., 0., 0., 0.] 107 ofunclist = [] 108 while(readsize): 109 readsize = filei.read(hopsize,myvec) 110 isonset,val = opick.do(myvec) 111 if (aubio_silence_detection(myvec(),silence)): 112 isonset=0 113 ovalist.append(val) 114 ovalist.pop(0) 115 ofunclist.append(val) 116 if (isonset == 1): 117 i=len(ovalist)-1 118 # find local minima before peak 119 while ovalist[i-1] < ovalist[i] and i > 0: 120 i -= 1 121 now = (frameread+1-i) 122 if now > 0 : 123 mylist.append(now) 124 else: 125 now = 0 126 mylist.append(now) 127 frameread += 1 128 return mylist, ofunclist 129 130 131 def getonsetscausal(filein,threshold,silence,bufsize=1024,hopsize=512,mode='dual'): 132 frameread = 0 133 filei = sndfile(filein) 134 channels = filei.channels() 135 myvec = fvec(hopsize,channels) 136 readsize = filei.read(hopsize,myvec) 137 opick = onsetpick(bufsize,hopsize,channels,myvec,threshold,mode=mode) 138 mylist = list() 139 while(readsize): 140 readsize = filei.read(hopsize,myvec) 141 isonset,val = opick.do(myvec) 142 if (aubio_silence_detection(myvec(),silence)): 143 isonset=0 144 if (isonset == 1): 145 now = frameread 146 if now > 0 : 147 mylist.append(now) 148 else: 149 now = 0 150 mylist.append(now) 151 frameread += 1 152 return mylist 153 154 155 def getonsets(filein,threshold=0.2,silence=-70.,bufsize=1024,hopsize=512,mode='dual'): 156 frameread = 0 157 filei = sndfile(filein) 158 channels = filei.channels() 159 samplerate= filei.samplerate() 160 myvec = fvec(hopsize,channels) 161 readsize = filei.read(hopsize,myvec) 162 opick = onsetpick(bufsize,hopsize,channels,myvec,threshold,mode=mode) 163 mylist = list() 164 #ovalist = [0., 0., 0., 0., 0., 0.] 165 ovalist = [0., 0., 0., 0., 0.] 166 while(readsize): 167 readsize = filei.read(hopsize,myvec) 168 isonset,val = opick.do(myvec) 169 if (aubio_silence_detection(myvec(),silence)): 170 isonset=0 171 ovalist.append(val) 172 ovalist.pop(0) 173 if (isonset == 1): 174 i=len(ovalist)-1 175 # find local minima before peak 176 while ovalist[i-1] < ovalist[i] and i > 0: 177 i -= 1 178 now = (frameread+1-i) 179 if now > 0 : 180 mylist.append(now) 181 else: 182 now = 0 183 mylist.append(now) 184 frameread += 1 185 return mylist 186 88 187 89 188 class pitchpick:
Note: See TracChangeset
for help on using the changeset viewer.