- Timestamp:
- Feb 15, 2006, 11:36:09 AM (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:
- 660c1d82
- Parents:
- e8d0c06
- Location:
- python
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
python/aubio/tasks.py
re8d0c06 rd9101a5 74 74 75 75 76 def getonsets(filein,threshold=0.2,silence=-70.,bufsize=1024,hopsize=512,77 mode='dual',localmin=False,storefunc=False,derivate=False):78 frameread = 079 filei = sndfile(filein)80 channels = filei.channels()81 myvec = fvec(hopsize,channels)82 readsize = filei.read(hopsize,myvec)83 opick = onsetpick(bufsize,hopsize,channels,myvec,threshold,84 mode=mode,derivate=derivate)85 mylist = list()86 if localmin:87 ovalist = [0., 0., 0., 0., 0.]88 ofunclist = []89 while(readsize):90 readsize = filei.read(hopsize,myvec)91 isonset,val = opick.do(myvec)92 if (aubio_silence_detection(myvec(),silence)):93 isonset=094 if localmin:95 if val > 0: ovalist.append(val)96 else: ovalist.append(0)97 ovalist.pop(0)98 if storefunc:99 ofunclist.append(val)100 if (isonset == 1):101 if localmin:102 i=len(ovalist)-1103 # find local minima before peak104 while ovalist[i-1] < ovalist[i] and i > 0:105 i -= 1106 now = (frameread+1-i)107 else:108 now = frameread109 if now > 0 :110 mylist.append(now)111 else:112 now = 0113 mylist.append(now)114 frameread += 1115 return mylist, ofunclist116 117 def cutfile(filein,slicetimes,zerothres=0.008,bufsize=1024,hopsize=512):118 frameread = 0119 readsize = hopsize120 filei = sndfile(filein)121 framestep = hopsize/(filei.samplerate()+0.)122 channels = filei.channels()123 newname = "%s%s%09.5f%s%s" % (filein.split(".")[0].split("/")[-1],".",124 frameread*framestep,".",filein.split(".")[-1])125 fileo = sndfile(newname,model=filei)126 myvec = fvec(hopsize,channels)127 mycopy = fvec(hopsize,channels)128 while(readsize==hopsize):129 readsize = filei.read(hopsize,myvec)130 # write to current file131 if len(slicetimes) and frameread >= slicetimes[0]:132 slicetimes.pop(0)133 # write up to 1st zero crossing134 zerocross = 0135 while ( abs( myvec.get(zerocross,0) ) > zerothres ):136 zerocross += 1137 writesize = fileo.write(zerocross,myvec)138 fromcross = 0139 while (zerocross < readsize):140 for i in range(channels):141 mycopy.set(myvec.get(zerocross,i),fromcross,i)142 fromcross += 1143 zerocross += 1144 del fileo145 fileo = sndfile("%s%s%09.5f%s%s" %146 (filein.split(".")[0].split("/")[-1],".",147 frameread*framestep,".",filein.split(".")[-1]),model=filei)148 writesize = fileo.write(fromcross,mycopy)149 else:150 writesize = fileo.write(readsize,myvec)151 frameread += 1152 del fileo153 154 155 def getsilences(filein,hopsize=512,silence=-70):156 frameread = 0157 filei = sndfile(filein)158 srate = filei.samplerate()159 channels = filei.channels()160 myvec = fvec(hopsize,channels)161 readsize = filei.read(hopsize,myvec)162 mylist = []163 wassilence = 0164 while(readsize==hopsize):165 readsize = filei.read(hopsize,myvec)166 if (aubio_silence_detection(myvec(),silence)==1):167 if wassilence == 0:168 mylist.append(frameread)169 wassilence == 1170 else: wassilence = 0171 frameread += 1172 return mylist173 174 175 def getpitch(filein,mode=aubio_pitch_mcomb,bufsize=1024,hopsize=512,omode=aubio_pitchm_freq,176 samplerate=44100.,silence=-70):177 frameread = 0178 filei = sndfile(filein)179 srate = filei.samplerate()180 channels = filei.channels()181 myvec = fvec(hopsize,channels)182 readsize = filei.read(hopsize,myvec)183 pitchdet = pitchdetection(mode=mode,bufsize=bufsize,hopsize=hopsize,184 channels=channels,samplerate=srate,omode=omode)185 mylist = []186 while(readsize==hopsize):187 readsize = filei.read(hopsize,myvec)188 freq = pitchdet(myvec)189 #print "%.3f %.2f" % (now,freq)190 if (aubio_silence_detection(myvec(),silence)!=1):191 mylist.append(freq)192 else:193 mylist.append(-1.)194 frameread += 1195 return mylist76 #def getonsets(filein,threshold=0.2,silence=-70.,bufsize=1024,hopsize=512, 77 # mode='dual',localmin=False,storefunc=False,derivate=False): 78 # frameread = 0 79 # filei = sndfile(filein) 80 # channels = filei.channels() 81 # myvec = fvec(hopsize,channels) 82 # readsize = filei.read(hopsize,myvec) 83 # opick = onsetpick(bufsize,hopsize,channels,myvec,threshold, 84 # mode=mode,derivate=derivate) 85 # mylist = list() 86 # if localmin: 87 # ovalist = [0., 0., 0., 0., 0.] 88 # ofunclist = [] 89 # while(readsize): 90 # readsize = filei.read(hopsize,myvec) 91 # isonset,val = opick.do(myvec) 92 # if (aubio_silence_detection(myvec(),silence)): 93 # isonset=0 94 # if localmin: 95 # if val > 0: ovalist.append(val) 96 # else: ovalist.append(0) 97 # ovalist.pop(0) 98 # if storefunc: 99 # ofunclist.append(val) 100 # if (isonset == 1): 101 # if localmin: 102 # i=len(ovalist)-1 103 # # find local minima before peak 104 # while ovalist[i-1] < ovalist[i] and i > 0: 105 # i -= 1 106 # now = (frameread+1-i) 107 # else: 108 # now = frameread 109 # if now > 0 : 110 # mylist.append(now) 111 # else: 112 # now = 0 113 # mylist.append(now) 114 # frameread += 1 115 # return mylist, ofunclist 116 # 117 #def cutfile(filein,slicetimes,zerothres=0.008,bufsize=1024,hopsize=512): 118 # frameread = 0 119 # readsize = hopsize 120 # filei = sndfile(filein) 121 # framestep = hopsize/(filei.samplerate()+0.) 122 # channels = filei.channels() 123 # newname = "%s%s%09.5f%s%s" % (filein.split(".")[0].split("/")[-1],".", 124 # frameread*framestep,".",filein.split(".")[-1]) 125 # fileo = sndfile(newname,model=filei) 126 # myvec = fvec(hopsize,channels) 127 # mycopy = fvec(hopsize,channels) 128 # while(readsize==hopsize): 129 # readsize = filei.read(hopsize,myvec) 130 # # write to current file 131 # if len(slicetimes) and frameread >= slicetimes[0]: 132 # slicetimes.pop(0) 133 # # write up to 1st zero crossing 134 # zerocross = 0 135 # while ( abs( myvec.get(zerocross,0) ) > zerothres ): 136 # zerocross += 1 137 # writesize = fileo.write(zerocross,myvec) 138 # fromcross = 0 139 # while (zerocross < readsize): 140 # for i in range(channels): 141 # mycopy.set(myvec.get(zerocross,i),fromcross,i) 142 # fromcross += 1 143 # zerocross += 1 144 # del fileo 145 # fileo = sndfile("%s%s%09.5f%s%s" % 146 # (filein.split(".")[0].split("/")[-1],".", 147 # frameread*framestep,".",filein.split(".")[-1]),model=filei) 148 # writesize = fileo.write(fromcross,mycopy) 149 # else: 150 # writesize = fileo.write(readsize,myvec) 151 # frameread += 1 152 # del fileo 153 # 154 # 155 #def getsilences(filein,hopsize=512,silence=-70): 156 # frameread = 0 157 # filei = sndfile(filein) 158 # srate = filei.samplerate() 159 # channels = filei.channels() 160 # myvec = fvec(hopsize,channels) 161 # readsize = filei.read(hopsize,myvec) 162 # mylist = [] 163 # wassilence = 0 164 # while(readsize==hopsize): 165 # readsize = filei.read(hopsize,myvec) 166 # if (aubio_silence_detection(myvec(),silence)==1): 167 # if wassilence == 0: 168 # mylist.append(frameread) 169 # wassilence == 1 170 # else: wassilence = 0 171 # frameread += 1 172 # return mylist 173 # 174 # 175 #def getpitch(filein,mode=aubio_pitch_mcomb,bufsize=1024,hopsize=512,omode=aubio_pitchm_freq, 176 # samplerate=44100.,silence=-70): 177 # frameread = 0 178 # filei = sndfile(filein) 179 # srate = filei.samplerate() 180 # channels = filei.channels() 181 # myvec = fvec(hopsize,channels) 182 # readsize = filei.read(hopsize,myvec) 183 # pitchdet = pitchdetection(mode=mode,bufsize=bufsize,hopsize=hopsize, 184 # channels=channels,samplerate=srate,omode=omode) 185 # mylist = [] 186 # while(readsize==hopsize): 187 # readsize = filei.read(hopsize,myvec) 188 # freq = pitchdet(myvec) 189 # #print "%.3f %.2f" % (now,freq) 190 # if (aubio_silence_detection(myvec(),silence)!=1): 191 # mylist.append(freq) 192 # else: 193 # mylist.append(-1.) 194 # frameread += 1 195 # return mylist 196 196 197 197 … … 219 219 parameters should be set *before* calling this method. 220 220 """ 221 import time 222 self.tic = time.time() 221 223 if params == None: self.params = taskparams() 222 224 else: self.params = params … … 230 232 self.myvec = fvec(self.params.hopsize,self.channels) 231 233 self.output = output 234 232 235 def __call__(self): 233 236 self.readsize = self.filei.read(self.params.hopsize,self.myvec) … … 249 252 """ Plot data """ 250 253 pass 254 255 def time(self): 256 import time 257 print "CPU time is now %f seconds," % time.clock(), 258 print "task execution took %f seconds" % (time.time() - self.tic) 251 259 252 260 class tasksilence(task): … … 317 325 return avgdist, meddist 318 326 319 def plot(self ):327 def plot(self,pitch,outplot=None): 320 328 from aubio.gnuplot import plot_pitch 321 329 plot_pitch(self.input, 322 330 pitch, 323 samplerate= samplerate,331 samplerate=float(self.srate), 324 332 hopsize=self.params.hopsize, 325 outplot=o ptions.outplot)333 outplot=outplot) 326 334 327 335 -
python/aubiocut
re8d0c06 rd9101a5 71 71 parser.add_option("-b","--beat", 72 72 action="store_true", dest="beat", default=False, 73 help=" NOT IMPLEMENTEDoutput beat locations")73 help="output beat locations") 74 74 (options, args) = parser.parse_args() 75 75 if not options.filename: -
python/aubiopitch
re8d0c06 rd9101a5 17 17 action="store", dest="filename", 18 18 help="input sound file") 19 parser.add_option("-m","--mode", action="callback", 20 callback=check_pitch_mode, dest="mode", 21 default=[aubio_pitch_mcomb], 19 parser.add_option("-m","--mode", 20 action="store", dest="mode", default='mcomb', 22 21 help="pitch detection mode [default=mcomb] \ 23 22 mcomb|yin|fcomb|schmitt") … … 86 85 87 86 filename = options.filename 88 samplerate = float(sndfile(filename).samplerate())89 hopsize = int(options.hopsize)90 bufsize = int(options.bufsize)91 step = float(samplerate)/float(hopsize)92 threshold = float(options.threshold)93 silence = float(options.silence)94 mode = options.mode 87 params = taskparams() 88 #params.samplerate = float(sndfile(filename).samplerate()) 89 params.hopsize = int(options.hopsize) 90 params.bufsize = int(options.bufsize) 91 #params.step = float(samplerate)/float(hopsize) 92 params.threshold = float(options.threshold) 93 params.silence = float(options.silence) 95 94 #mintol = float(options.mintol)*step 96 95 # default take back system delay 97 96 if options.delay: delay = float(options.delay) 98 else: delay = 2./ step97 else: delay = 2./params.step 99 98 100 99 if options.note: 101 100 exit("not implemented yet") 102 else:103 pitch = []104 for i in range(len(mode)):105 pitch.append(getpitch(filename, #threshold,106 mode=mode[i],107 omode=options.omode,108 bufsize=bufsize,hopsize=hopsize,109 silence=silence))110 for j in range(len(pitch[i])):111 if pitch[i][j] > 1500 or pitch[i][j] < 40:112 pitch[i][j] = 0.;113 101 114 ## take back system delay115 #if delay != 0:116 # for i in range(len(onsets)):117 # onsets[i] -= delay*step118 #119 ## prune doubled120 #if mintol > 0:121 # last = -2*mintol122 # newonsets = []123 # for new in onsets:124 # if (new - last > mintol):125 # newonsets.append(new)126 # last = new127 # onsets = newonsets128 102 129 # print times in second 130 if options.verbose: 131 for j in range(len(pitch[0])): 132 print "%f\t" % (j/step), 133 for i in range(len(pitch)): 134 print "%f\t" % pitch[i][j], 135 print 103 pitch = [] 104 modes = options.mode.split(',') 105 for i in range(len(modes)): 106 params.pitchmode = modes[i] 107 dotask = taskpitch 108 #pitch.append(getpitch(filename, #threshold, 109 # mode=mode[i], 110 # omode=options.omode, 111 # bufsize=bufsize,hopsize=hopsize, 112 # silence=silence)) 113 filetask = dotask(filename,params=params) 114 pitch.append(filetask.compute_all()) 115 for j in range(len(pitch[i])): 116 if pitch[i][j] > 10000 or pitch[i][j] < 40: 117 pitch[i][j] = 0.; 136 118 137 if options.plot: 138 from aubio.gnuplot import plot_pitch 139 plot_pitch(filename, pitch, 140 samplerate=samplerate, hopsize=hopsize, outplot=options.outplot) 119 if options.verbose: 120 for j in range(len(pitch[i])): 121 print "%f\t" % (j/params.step), 122 print "%f\t" % pitch[i][j], 123 print 124 125 if options.plot: 126 filetask.plot(pitch,outplot=options.outplot)
Note: See TracChangeset
for help on using the changeset viewer.