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
7373 sys.exit(1)
7474
7575
76−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
76+#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
196196
197197
198198 class taskparams(object):
@@ -218,6 +218,8 @@ class task(taskparams): · 19 unmodified lines
218218 """ open the input file and initialize default argument
219219 parameters should be set *before* calling this method.
220220 """
221+ import time
222+ self.tic = time.time()
221223 if params == None: self.params = taskparams()
222224 else: self.params = params
223225 self.frameread = 0
@@ -229,6 +231,7 @@ class task(taskparams): · 5 unmodified lines
229231 self.step = float(self.srate)/float(self.params.hopsize)
230232 self.myvec = fvec(self.params.hopsize,self.channels)
231233 self.output = output
234+
232235 def __call__(self):
233236 self.readsize = self.filei.read(self.params.hopsize,self.myvec)
234237 self.frameread += 1
@@ -249,6 +252,11 @@ class task(taskparams): · 14 unmodified lines
249252 """ Plot data """
250253 pass
251254
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+
252260 class tasksilence(task):
253261 wassilence = 1
254262 issilence = 1
@@ -316,13 +324,13 @@ class taskpitch(task): · 61 unmodified lines
316324 meddist = self.truth - med
317325 return avgdist, meddist
318326
319− def plot(self):
327+ def plot(self,pitch,outplot=None):
320328 from aubio.gnuplot import plot_pitch
321329 plot_pitch(self.input,
322330 pitch,
323− samplerate=samplerate,
331+ samplerate=float(self.srate),
324332 hopsize=self.params.hopsize,
325− outplot=options.outplot)
333+ outplot=outplot)
326334
327335
328336 class taskonset(task):
python/aubiocut+1−1
@@ -70,7 +70,7 @@ def parse_args(): · 69 unmodified lines
7070 # to be implemented
7171 parser.add_option("-b","--beat",
7272 action="store_true", dest="beat", default=False,
73− help="NOT IMPLEMENTED output beat locations")
73+ help="output beat locations")
7474 (options, args) = parser.parse_args()
7575 if not options.filename:
7676 print "no file name given\n", usage
python/aubiopitch+33−47
@@ -16,9 +16,8 @@ def parse_args(): · 15 unmodified lines
1616 parser.add_option("-i","--input",
1717 action="store", dest="filename",
1818 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',
2221 help="pitch detection mode [default=mcomb] \
2322 mcomb|yin|fcomb|schmitt")
2423 parser.add_option("-u","--units", action="callback",
@@ -85,56 +84,43 @@ options, args = parse_args() · 60 unmodified lines
8584 #print options.bufsize, options.hopsize
8685
8786 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)
9594 #mintol = float(options.mintol)*step
9695 # default take back system delay
9796 if options.delay: delay = float(options.delay)
98−else: delay = 2./step
97+else: delay = 2./params.step
9998
10099 if options.note:
101100 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.;
113101
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
128102
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.;
136118
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)

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