Changeset 5e491b3b for python/aubio/aubioclass.py
- Timestamp:
- Aug 28, 2005, 7:58:31 PM (19 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:
- 3c86eb1
- Parents:
- 4cc9fe5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/aubio/aubioclass.py
r4cc9fe5 r5e491b3b 106 106 return self.pp.do(self.myonset),self.myonset.get(0,0) 107 107 108 def check_onset_mode(option, opt, value, parser):109 nvalue = parser.rargs[0]110 if nvalue == 'complexdomain' or nvalue == 'complex' :111 setattr(parser.values, option.dest, aubio_onset_complex)112 elif nvalue == 'hfc' :113 setattr(parser.values, option.dest, aubio_onset_hfc)114 elif nvalue == 'phase' :115 setattr(parser.values, option.dest, aubio_onset_phase)116 elif nvalue == 'specdiff' :117 setattr(parser.values, option.dest, aubio_onset_specdiff)118 elif nvalue == 'energy' :119 setattr(parser.values, option.dest, aubio_onset_energy)120 elif nvalue == 'kl' :121 setattr(parser.values, option.dest, aubio_onset_kl)122 elif nvalue == 'mkl' :123 setattr(parser.values, option.dest, aubio_onset_mkl)124 elif nvalue == 'dual' :125 setattr(parser.values, option.dest, 'dual')126 else:127 print "unknown onset detection function selected"128 sys.exit(1)129 130 def check_pitch_mode(option, opt, value, parser):131 nvalue = parser.rargs[0]132 if nvalue == 'mcomb' :133 setattr(parser.values, option.dest, aubio_pitch_mcomb)134 elif nvalue == 'yin' :135 setattr(parser.values, option.dest, aubio_pitch_yin)136 elif nvalue == 'fcomb' :137 setattr(parser.values, option.dest, aubio_pitch_fcomb)138 elif nvalue == 'schmitt':139 setattr(parser.values, option.dest, aubio_pitch_schmitt)140 else:141 print "error: unknown pitch detection function selected"142 sys.exit(1)143 144 def check_pitchm_mode(option, opt, value, parser):145 nvalue = parser.rargs[0]146 if nvalue == 'freq' :147 setattr(parser.values, option.dest, aubio_pitchm_freq)148 elif nvalue == 'midi' :149 setattr(parser.values, option.dest, aubio_pitchm_midi)150 elif nvalue == 'cent' :151 setattr(parser.values, option.dest, aubio_pitchm_cent)152 elif nvalue == 'bin' :153 setattr(parser.values, option.dest, aubio_pitchm_bin)154 else:155 print "error: unknown pitch detection output selected"156 sys.exit(1)157 158 159 def getonsets(filein,threshold=0.2,silence=-70.,bufsize=1024,hopsize=512,160 mode='dual',localmin=False,storefunc=False,derivate=False):161 frameread = 0162 filei = sndfile(filein)163 channels = filei.channels()164 myvec = fvec(hopsize,channels)165 readsize = filei.read(hopsize,myvec)166 opick = onsetpick(bufsize,hopsize,channels,myvec,threshold,167 mode=mode,derivate=derivate)168 mylist = list()169 if localmin:170 ovalist = [0., 0., 0., 0., 0.]171 if storefunc:172 ofunclist = []173 while(readsize):174 readsize = filei.read(hopsize,myvec)175 isonset,val = opick.do(myvec)176 if (aubio_silence_detection(myvec(),silence)):177 isonset=0178 if localmin:179 if val > 0: ovalist.append(val)180 else: ovalist.append(0)181 ovalist.pop(0)182 if storefunc:183 ofunclist.append(val)184 if (isonset == 1):185 if localmin:186 i=len(ovalist)-1187 # find local minima before peak188 while ovalist[i-1] < ovalist[i] and i > 0:189 i -= 1190 now = (frameread+1-i)191 else:192 now = frameread193 if now > 0 :194 mylist.append(now)195 else:196 now = 0197 mylist.append(now)198 frameread += 1199 if storefunc: return mylist, ofunclist200 else: return mylist201 202 def cutfile(filein,slicetimes,zerothres=0.008,bufsize=1024,hopsize=512):203 frameread = 0204 readsize = hopsize205 filei = sndfile(filein)206 framestep = hopsize/(filei.samplerate()+0.)207 channels = filei.channels()208 newname = "%s%s%09.5f%s%s" % (filein.split(".")[0].split("/")[-1],".",209 frameread*framestep,".",filein.split(".")[-1])210 fileo = sndfile(newname,model=filei)211 myvec = fvec(hopsize,channels)212 mycopy = fvec(hopsize,channels)213 while(readsize==hopsize):214 readsize = filei.read(hopsize,myvec)215 # write to current file216 if len(slicetimes) and frameread >= slicetimes[0]:217 slicetimes.pop(0)218 # write up to 1st zero crossing219 zerocross = 0220 while ( abs( myvec.get(zerocross,0) ) > zerothres ):221 zerocross += 1222 writesize = fileo.write(zerocross,myvec)223 fromcross = 0224 while (zerocross < readsize):225 for i in range(channels):226 mycopy.set(myvec.get(zerocross,i),fromcross,i)227 fromcross += 1228 zerocross += 1229 del fileo230 fileo = sndfile("%s%s%09.5f%s%s" %231 (filein.split(".")[0].split("/")[-1],".",232 frameread*framestep,".",filein.split(".")[-1]),model=filei)233 writesize = fileo.write(fromcross,mycopy)234 else:235 writesize = fileo.write(readsize,myvec)236 frameread += 1237 del fileo238 239 240 def getsilences(filein,hopsize=512,silence=-70):241 frameread = 0242 filei = sndfile(filein)243 srate = filei.samplerate()244 channels = filei.channels()245 myvec = fvec(hopsize,channels)246 readsize = filei.read(hopsize,myvec)247 mylist = []248 wassilence = 0249 while(readsize==hopsize):250 readsize = filei.read(hopsize,myvec)251 if (aubio_silence_detection(myvec(),silence)==1):252 if wassilence == 0:253 mylist.append(frameread)254 wassilence == 1255 else: wassilence = 0256 frameread += 1257 return mylist258 259 def getpitch(filein,mode=aubio_pitch_mcomb,bufsize=1024,hopsize=512,omode=aubio_pitchm_freq,260 samplerate=44100.,silence=-70):261 frameread = 0262 filei = sndfile(filein)263 srate = filei.samplerate()264 channels = filei.channels()265 myvec = fvec(hopsize,channels)266 readsize = filei.read(hopsize,myvec)267 pitchdet = pitchdetection(mode=mode,bufsize=bufsize,hopsize=hopsize,268 channels=channels,samplerate=srate,omode=omode)269 mylist = []270 while(readsize==hopsize):271 readsize = filei.read(hopsize,myvec)272 freq = pitchdet(myvec)273 #print "%.3f %.2f" % (now,freq)274 if (aubio_silence_detection(myvec(),silence)!=1):275 mylist.append(freq)276 else:277 mylist.append(-1.)278 frameread += 1279 return mylist280 281 108 class pitchdetection: 282 109 def __init__(self,mode=aubio_pitch_mcomb,bufsize=2048,hopsize=1024,
Note: See TracChangeset
for help on using the changeset viewer.