History

move aubiopitch to new tasks, comment out old task versions move aubiopitch to new tasks, comment out old task versions

Paul Brossier committed 20 years ago

Commit d9101a51 parent e8d0c063 files · +165 −171Browse files

Showing the changes to python (3 of 3 files). Show all

Unified · Split

3 files
  1. python/aubio/tasks.py +131 −123
  2. python/aubiocut +1 −1
  3. python/aubiopitch +33 −47
python/aubio/tasks.py+131−123
@@ -73,126 +73,126 @@ def check_pitchm_mode(option, opt, value, parser): · 72 unmodified lines
73 sys.exit(1)73 sys.exit(1)
74 74
75 75
76def getonsets(filein,threshold=0.2,silence=-70.,bufsize=1024,hopsize=512,76#def getonsets(filein,threshold=0.2,silence=-70.,bufsize=1024,hopsize=512,
77 mode='dual',localmin=False,storefunc=False,derivate=False):77# mode='dual',localmin=False,storefunc=False,derivate=False):
78 frameread = 078# frameread = 0
79 filei = sndfile(filein)79# filei = sndfile(filein)
80 channels = filei.channels()80# channels = filei.channels()
81 myvec = fvec(hopsize,channels)81# myvec = fvec(hopsize,channels)
82 readsize = filei.read(hopsize,myvec)82# readsize = filei.read(hopsize,myvec)
83 opick = onsetpick(bufsize,hopsize,channels,myvec,threshold,83# opick = onsetpick(bufsize,hopsize,channels,myvec,threshold,
84 mode=mode,derivate=derivate)84# mode=mode,derivate=derivate)
85 mylist = list()85# mylist = list()
86 if localmin:86# if localmin:
87 ovalist = [0., 0., 0., 0., 0.]87# ovalist = [0., 0., 0., 0., 0.]
88 ofunclist = []88# ofunclist = []
89 while(readsize):89# while(readsize):
90 readsize = filei.read(hopsize,myvec)90# readsize = filei.read(hopsize,myvec)
91 isonset,val = opick.do(myvec)91# isonset,val = opick.do(myvec)
92 if (aubio_silence_detection(myvec(),silence)):92# if (aubio_silence_detection(myvec(),silence)):
93 isonset=093# isonset=0
94 if localmin:94# if localmin:
95 if val > 0: ovalist.append(val)95# if val > 0: ovalist.append(val)
96 else: ovalist.append(0)96# else: ovalist.append(0)
97 ovalist.pop(0)97# ovalist.pop(0)
98 if storefunc:98# if storefunc:
99 ofunclist.append(val)99# ofunclist.append(val)
100 if (isonset == 1):100# if (isonset == 1):
101 if localmin:101# if localmin:
102 i=len(ovalist)-1102# i=len(ovalist)-1
103 # find local minima before peak 103# # find local minima before peak
104 while ovalist[i-1] < ovalist[i] and i > 0:104# while ovalist[i-1] < ovalist[i] and i > 0:
105 i -= 1105# i -= 1
106 now = (frameread+1-i)106# now = (frameread+1-i)
107 else:107# else:
108 now = frameread108# now = frameread
109 if now > 0 :109# if now > 0 :
110 mylist.append(now)110# mylist.append(now)
111 else:111# else:
112 now = 0112# now = 0
113 mylist.append(now)113# mylist.append(now)
114 frameread += 1114# frameread += 1
115 return mylist, ofunclist115# return mylist, ofunclist
116 116#
117def cutfile(filein,slicetimes,zerothres=0.008,bufsize=1024,hopsize=512):117#def cutfile(filein,slicetimes,zerothres=0.008,bufsize=1024,hopsize=512):
118 frameread = 0118# frameread = 0
119 readsize = hopsize 119# readsize = hopsize
120 filei = sndfile(filein)120# filei = sndfile(filein)
121 framestep = hopsize/(filei.samplerate()+0.)121# framestep = hopsize/(filei.samplerate()+0.)
122 channels = filei.channels()122# channels = filei.channels()
123 newname = "%s%s%09.5f%s%s" % (filein.split(".")[0].split("/")[-1],".",123# newname = "%s%s%09.5f%s%s" % (filein.split(".")[0].split("/")[-1],".",
124 frameread*framestep,".",filein.split(".")[-1])124# frameread*framestep,".",filein.split(".")[-1])
125 fileo = sndfile(newname,model=filei)125# fileo = sndfile(newname,model=filei)
126 myvec = fvec(hopsize,channels)126# myvec = fvec(hopsize,channels)
127 mycopy = fvec(hopsize,channels)127# mycopy = fvec(hopsize,channels)
128 while(readsize==hopsize):128# while(readsize==hopsize):
129 readsize = filei.read(hopsize,myvec)129# readsize = filei.read(hopsize,myvec)
130 # write to current file130# # write to current file
131 if len(slicetimes) and frameread >= slicetimes[0]:131# if len(slicetimes) and frameread >= slicetimes[0]:
132 slicetimes.pop(0)132# slicetimes.pop(0)
133 # write up to 1st zero crossing133# # write up to 1st zero crossing
134 zerocross = 0134# zerocross = 0
135 while ( abs( myvec.get(zerocross,0) ) > zerothres ):135# while ( abs( myvec.get(zerocross,0) ) > zerothres ):
136 zerocross += 1136# zerocross += 1
137 writesize = fileo.write(zerocross,myvec)137# writesize = fileo.write(zerocross,myvec)
138 fromcross = 0138# fromcross = 0
139 while (zerocross < readsize):139# while (zerocross < readsize):
140 for i in range(channels):140# for i in range(channels):
141 mycopy.set(myvec.get(zerocross,i),fromcross,i)141# mycopy.set(myvec.get(zerocross,i),fromcross,i)
142 fromcross += 1142# fromcross += 1
143 zerocross += 1143# zerocross += 1
144 del fileo144# del fileo
145 fileo = sndfile("%s%s%09.5f%s%s" % 145# fileo = sndfile("%s%s%09.5f%s%s" %
146 (filein.split(".")[0].split("/")[-1],".",146# (filein.split(".")[0].split("/")[-1],".",
147 frameread*framestep,".",filein.split(".")[-1]),model=filei)147# frameread*framestep,".",filein.split(".")[-1]),model=filei)
148 writesize = fileo.write(fromcross,mycopy)148# writesize = fileo.write(fromcross,mycopy)
149 else:149# else:
150 writesize = fileo.write(readsize,myvec)150# writesize = fileo.write(readsize,myvec)
151 frameread += 1151# frameread += 1
152 del fileo152# del fileo
153 153#
154 154#
155def getsilences(filein,hopsize=512,silence=-70):155#def getsilences(filein,hopsize=512,silence=-70):
156 frameread = 0156# frameread = 0
157 filei = sndfile(filein)157# filei = sndfile(filein)
158 srate = filei.samplerate()158# srate = filei.samplerate()
159 channels = filei.channels()159# channels = filei.channels()
160 myvec = fvec(hopsize,channels)160# myvec = fvec(hopsize,channels)
161 readsize = filei.read(hopsize,myvec)161# readsize = filei.read(hopsize,myvec)
162 mylist = []162# mylist = []
163 wassilence = 0163# wassilence = 0
164 while(readsize==hopsize):164# while(readsize==hopsize):
165 readsize = filei.read(hopsize,myvec)165# readsize = filei.read(hopsize,myvec)
166 if (aubio_silence_detection(myvec(),silence)==1):166# if (aubio_silence_detection(myvec(),silence)==1):
167 if wassilence == 0:167# if wassilence == 0:
168 mylist.append(frameread)168# mylist.append(frameread)
169 wassilence == 1169# wassilence == 1
170 else: wassilence = 0170# else: wassilence = 0
171 frameread += 1171# frameread += 1
172 return mylist172# return mylist
173 173#
174 174#
175def getpitch(filein,mode=aubio_pitch_mcomb,bufsize=1024,hopsize=512,omode=aubio_pitchm_freq,175#def getpitch(filein,mode=aubio_pitch_mcomb,bufsize=1024,hopsize=512,omode=aubio_pitchm_freq,
176 samplerate=44100.,silence=-70):176# samplerate=44100.,silence=-70):
177 frameread = 0177# frameread = 0
178 filei = sndfile(filein)178# filei = sndfile(filein)
179 srate = filei.samplerate()179# srate = filei.samplerate()
180 channels = filei.channels()180# channels = filei.channels()
181 myvec = fvec(hopsize,channels)181# myvec = fvec(hopsize,channels)
182 readsize = filei.read(hopsize,myvec)182# readsize = filei.read(hopsize,myvec)
183 pitchdet = pitchdetection(mode=mode,bufsize=bufsize,hopsize=hopsize,183# pitchdet = pitchdetection(mode=mode,bufsize=bufsize,hopsize=hopsize,
184 channels=channels,samplerate=srate,omode=omode)184# channels=channels,samplerate=srate,omode=omode)
185 mylist = []185# mylist = []
186 while(readsize==hopsize):186# while(readsize==hopsize):
187 readsize = filei.read(hopsize,myvec)187# readsize = filei.read(hopsize,myvec)
188 freq = pitchdet(myvec)188# freq = pitchdet(myvec)
189 #print "%.3f %.2f" % (now,freq)189# #print "%.3f %.2f" % (now,freq)
190 if (aubio_silence_detection(myvec(),silence)!=1):190# if (aubio_silence_detection(myvec(),silence)!=1):
191 mylist.append(freq)191# mylist.append(freq)
192 else: 192# else:
193 mylist.append(-1.)193# mylist.append(-1.)
194 frameread += 1194# frameread += 1
195 return mylist195# return mylist
196 196
197 197
198class taskparams(object):198class taskparams(object):
@@ -218,6 +218,8 @@ class task(taskparams): · 19 unmodified lines
218 """ open the input file and initialize default argument 218 """ open the input file and initialize default argument
219 parameters should be set *before* calling this method.219 parameters should be set *before* calling this method.
220 """220 """
221 import time
222 self.tic = time.time()
221 if params == None: self.params = taskparams()223 if params == None: self.params = taskparams()
222 else: self.params = params224 else: self.params = params
223 self.frameread = 0225 self.frameread = 0
@@ -229,6 +231,7 @@ class task(taskparams): · 5 unmodified lines
229 self.step = float(self.srate)/float(self.params.hopsize)231 self.step = float(self.srate)/float(self.params.hopsize)
230 self.myvec = fvec(self.params.hopsize,self.channels)232 self.myvec = fvec(self.params.hopsize,self.channels)
231 self.output = output233 self.output = output
234
232 def __call__(self):235 def __call__(self):
233 self.readsize = self.filei.read(self.params.hopsize,self.myvec)236 self.readsize = self.filei.read(self.params.hopsize,self.myvec)
234 self.frameread += 1237 self.frameread += 1
@@ -249,6 +252,11 @@ class task(taskparams): · 14 unmodified lines
249 """ Plot data """252 """ Plot data """
250 pass253 pass
251 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)
259
252class tasksilence(task):260class tasksilence(task):
253 wassilence = 1261 wassilence = 1
254 issilence = 1262 issilence = 1
@@ -316,13 +324,13 @@ class taskpitch(task): · 61 unmodified lines
316 meddist = self.truth - med324 meddist = self.truth - med
317 return avgdist, meddist325 return avgdist, meddist
318 326
319 def plot(self):327 def plot(self,pitch,outplot=None):
320 from aubio.gnuplot import plot_pitch328 from aubio.gnuplot import plot_pitch
321 plot_pitch(self.input, 329 plot_pitch(self.input,
322 pitch, 330 pitch,
323 samplerate=samplerate, 331 samplerate=float(self.srate),
324 hopsize=self.params.hopsize, 332 hopsize=self.params.hopsize,
325 outplot=options.outplot)333 outplot=outplot)
326 334
327 335
328class taskonset(task):336class taskonset(task):
python/aubiocut+1−1
@@ -70,7 +70,7 @@ def parse_args(): · 69 unmodified lines
70 # to be implemented70 # to be implemented
71 parser.add_option("-b","--beat",71 parser.add_option("-b","--beat",
72 action="store_true", dest="beat", default=False,72 action="store_true", dest="beat", default=False,
73 help="NOT IMPLEMENTED output beat locations")73 help="output beat locations")
74 (options, args) = parser.parse_args()74 (options, args) = parser.parse_args()
75 if not options.filename: 75 if not options.filename:
76 print "no file name given\n", usage76 print "no file name given\n", usage
python/aubiopitch+33−47
@@ -16,9 +16,8 @@ def parse_args(): · 15 unmodified lines
16 parser.add_option("-i","--input",16 parser.add_option("-i","--input",
17 action="store", dest="filename", 17 action="store", dest="filename",
18 help="input sound file")18 help="input sound file")
19 parser.add_option("-m","--mode", action="callback", 19 parser.add_option("-m","--mode",
20 callback=check_pitch_mode, dest="mode", 20 action="store", dest="mode", default='mcomb',
21 default=[aubio_pitch_mcomb],
22 help="pitch detection mode [default=mcomb] \21 help="pitch detection mode [default=mcomb] \
23 mcomb|yin|fcomb|schmitt")22 mcomb|yin|fcomb|schmitt")
24 parser.add_option("-u","--units", action="callback", 23 parser.add_option("-u","--units", action="callback",
@@ -85,56 +84,43 @@ options, args = parse_args() · 60 unmodified lines
85#print options.bufsize, options.hopsize84#print options.bufsize, options.hopsize
86 85
87filename = options.filename86filename = options.filename
88samplerate = float(sndfile(filename).samplerate())87params = taskparams()
89hopsize = int(options.hopsize)88#params.samplerate = float(sndfile(filename).samplerate())
90bufsize = int(options.bufsize)89params.hopsize = int(options.hopsize)
91step = float(samplerate)/float(hopsize)90params.bufsize = int(options.bufsize)
92threshold = float(options.threshold)91#params.step = float(samplerate)/float(hopsize)
93silence = float(options.silence)92params.threshold = float(options.threshold)
94mode = options.mode93params.silence = float(options.silence)
95#mintol = float(options.mintol)*step94#mintol = float(options.mintol)*step
96# default take back system delay95# default take back system delay
97if options.delay: delay = float(options.delay)96if options.delay: delay = float(options.delay)
98else: delay = 2./step97else: delay = 2./params.step
99 98
100if options.note:99if options.note:
101 exit("not implemented yet")100 exit("not implemented yet")
102else:
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 delay
115#if delay != 0:
116# for i in range(len(onsets)):
117# onsets[i] -= delay*step
118#
119## prune doubled
120#if mintol > 0:
121# last = -2*mintol
122# newonsets = []
123# for new in onsets:
124# if (new - last > mintol):
125# newonsets.append(new)
126# last = new
127# onsets = newonsets
128 102
129# print times in second103pitch = []
130if options.verbose:104modes = options.mode.split(',')
131 for j in range(len(pitch[0])): 105for i in range(len(modes)):
132 print "%f\t" % (j/step),106 params.pitchmode = modes[i]
133 for i in range(len(pitch)): 107 dotask = taskpitch
134 print "%f\t" % pitch[i][j],108 #pitch.append(getpitch(filename, #threshold,
135 print109 # 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
137if options.plot:119 if options.verbose:
138 from aubio.gnuplot import plot_pitch120 for j in range(len(pitch[i])):
139 plot_pitch(filename, pitch, 121 print "%f\t" % (j/params.step),
140 samplerate=samplerate, hopsize=hopsize, outplot=options.outplot)122 print "%f\t" % pitch[i][j],
123 print
124
125 if options.plot:
126 filetask.plot(pitch,outplot=options.outplot)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t