Index: python/aubio/tasks.py
===================================================================
--- python/aubio/tasks.py	(revision 37f0352efc6098d49213d0405aa0270b6d5de330)
+++ python/aubio/tasks.py	(revision 84e80a1e3ad363119f939b73210b4fc27f5a6218)
@@ -201,5 +201,5 @@
 		self.derivate = False
 		self.localmin = False
-		self.delay = 0.
+		self.delay = 4.
 		self.storefunc = False
 		self.bufsize = 512
@@ -212,5 +212,7 @@
 		self.onsetmode = 'dual'
 		self.pitchmode = 'yin'
+		self.dcthreshold = -1.
 		self.omode = aubio_pitchm_freq
+		self.verbose   = False
 
 class task(taskparams):
@@ -230,5 +232,5 @@
 		self.srate     = self.filei.samplerate()
 		self.channels  = self.filei.channels()
-		self.step      = float(self.srate)/float(self.params.hopsize)
+		self.params.step = float(self.params.hopsize)/float(self.srate)
 		self.myvec     = fvec(self.params.hopsize,self.channels)
 		self.output    = output
@@ -243,6 +245,12 @@
 		while(self.readsize==self.params.hopsize):
 			tmp = self()
-			if tmp: mylist.append(tmp)
+			if tmp: 
+				mylist.append(tmp)
+				if self.params.verbose:
+					self.fprint(tmp)
     		return mylist
+	
+	def fprint(self,foo):
+		print foo
 
 	def eval(self,results):
@@ -273,7 +281,12 @@
 			self.wassilence = 0
 		if self.issilence == -1:
-			return self.frameread, -1
+			return max(self.frameread-self.params.delay,0.), -1
 		elif self.issilence == 2:
-			return self.frameread, 2 
+			return max(self.frameread+self.params.delay,0.), 2 
+
+	def fprint(self,foo):
+		print self.params.step*foo[0],
+		if foo[1] == 2: print "OFF"
+		else: print "ON"
 
 class taskpitch(task):
@@ -344,8 +357,8 @@
 			self.params.threshold,
 			mode=get_onset_mode(self.params.onsetmode),
+			dcthreshold=self.params.dcthreshold,
 			derivate=self.params.derivate)
 		self.olist = [] 
 		self.ofunc = []
-		self.d,self.d2 = [],[]
 		self.maxofunc = 0
 		self.last = 0
@@ -366,6 +379,6 @@
                 if (isonset == 1):
                         if self.params.localmin:
+                                # find local minima before peak 
                                 i=len(self.ovalist)-1
-                                # find local minima before peak 
                                 while self.ovalist[i-1] < self.ovalist[i] and i > 0:
                                         i -= 1
@@ -373,9 +386,10 @@
                         else:
                                 now = self.frameread
+			# take back delay
 			if self.params.delay != 0.: now -= self.params.delay
                         if now < 0 :
                                 now = 0
 			if self.params.mintol:
-				#print now - self.last, self.params.mintol
+				# prune doubled 
 				if (now - self.last) > self.params.mintol:
 					self.last = now
@@ -384,4 +398,7 @@
 				return now, val 
 
+
+	def fprint(self,foo):
+		print self.params.step*foo[0]
 
 	def eval(self,inputdata,ftru,mode='roc',vmode=''):
@@ -414,5 +431,5 @@
 				onset_rocloc(ltru,lres,self.params.tol)
 
-	def plot(self,onsets,ofunc):
+	def plot(self,onsets,ofunc,wplot,oplots,nplot=False):
 		import Gnuplot, Gnuplot.funcutils
 		import aubio.txtfile
@@ -421,15 +438,26 @@
 		from aubio.onsetcompare import onset_roc
 
+		x1,y1,y1p = [],[],[]
+		oplot = []
+
 		self.lenofunc = len(ofunc) 
-		self.maxofunc = max(max(ofunc), self.maxofunc)
+		self.maxofunc = max(ofunc)
 		# onset detection function 
-		downtime = numarray.arange(len(ofunc))/self.step
-		self.d.append(Gnuplot.Data(downtime,ofunc,with='lines'))
+		downtime = numarray.arange(len(ofunc))*self.params.step
+		oplot.append(Gnuplot.Data(downtime,ofunc,with='lines',title=self.params.onsetmode))
 
 		# detected onsets
-		x1 = numarray.array(onsets)/self.step
-		y1 = self.maxofunc*numarray.ones(len(onsets))
-		self.d.append(Gnuplot.Data(x1,y1,with='impulses'))
-		self.d2.append(Gnuplot.Data(x1,-y1,with='impulses'))
+		if not nplot:
+			for i in onsets:
+				x1.append(i[0]*self.params.step)
+				y1.append(self.maxofunc)
+				y1p.append(-self.maxofunc)
+			#x1 = numarray.array(onsets)*self.params.step
+			#y1 = self.maxofunc*numarray.ones(len(onsets))
+			if x1:
+				oplot.append(Gnuplot.Data(x1,y1,with='impulses'))
+				wplot.append(Gnuplot.Data(x1,y1p,with='impulses'))
+
+		oplots.append(oplot)
 
 		# check if datafile exists truth
@@ -437,11 +465,11 @@
 		if datafile == self.input: datafile = ""
 		if not os.path.isfile(datafile):
-			self.title = "truth file not found"
+			self.title = "" #"(no ground truth)"
 			t = Gnuplot.Data(0,0,with='impulses') 
 		else:
 			t_onsets = aubio.txtfile.read_datafile(datafile)
+			x2 = numarray.array(t_onsets).resize(len(t_onsets))
 			y2 = self.maxofunc*numarray.ones(len(t_onsets))
-			x2 = numarray.array(t_onsets).resize(len(t_onsets))
-			self.d2.append(Gnuplot.Data(x2,y2,with='impulses'))
+			wplot.append(Gnuplot.Data(x2,y2,with='impulses'))
 			
 			tol = 0.050 
@@ -454,19 +482,33 @@
 
 
-	def plotplot(self,outplot=None):
+	def plotplot(self,wplot,oplot,outplot=None):
 		from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot
 		import re
 		# audio data
 		time,data = audio_to_array(self.input)
-		self.d2.append(make_audio_plot(time,data))
+		wplot = [make_audio_plot(time,data)] + wplot
 		# prepare the plot
 		g = gnuplot_init(outplot)
 
+		g('set multiplot')
+
+		# hack to align left axis
+		g('set lmargin 6')
+		g('set tmargin 0')
+		g('set format x ""')
+		g('set format y ""')
+		g('set noytics')
+
+		for i in range(len(oplot)):
+			# plot onset detection functions
+			g('set size 1,%f' % (0.7/(len(oplot))))
+			g('set origin 0,%f' % (float(i)*0.7/(len(oplot))))
+			g('set xrange [0:%f]' % (self.lenofunc*self.params.step))
+			g.plot(*oplot[i])
+
+		g('set tmargin 3')
+		g('set format x "%10.1f"')
+
 		g('set title \'%s %s\'' % (re.sub('.*/','',self.input),self.title))
-
-		g('set multiplot')
-
-		# hack to align left axis
-		g('set lmargin 15')
 
 		# plot waveform and onsets
@@ -476,17 +518,6 @@
 		g('set yrange [-1:1]') 
 		g.ylabel('amplitude')
-		g.plot(*self.d2)
+		g.plot(*wplot)
 		
-		g('unset title')
-
-		# plot onset detection function
-		g('set size 1,0.7')
-		g('set origin 0,0')
-		g('set xrange [0:%f]' % (self.lenofunc/self.step))
-		g('set yrange [0:%f]' % (self.maxofunc*1.01))
-		g.xlabel('time')
-		g.ylabel('onset detection value')
-		g.plot(*self.d)
-
 		g('unset multiplot')
 
@@ -498,7 +529,7 @@
 		task.__init__(self,input,output=None,params=params)
 		self.newname   = "%s%s%09.5f%s%s" % (self.input.split(".")[0].split("/")[-1],".",
-					self.frameread/self.step,".",self.input.split(".")[-1])
-		self.fileo	 = sndfile(self.newname,model=self.filei)
-		self.myvec	 = fvec(self.params.hopsize,self.channels)
+					self.frameread*self.params.step,".",self.input.split(".")[-1])
+		self.fileo	= sndfile(self.newname,model=self.filei)
+		self.myvec	= fvec(self.params.hopsize,self.channels)
 		self.mycopy	= fvec(self.params.hopsize,self.channels)
 		self.slicetimes = slicetimes 
@@ -507,5 +538,5 @@
 		task.__call__(self)
 		# write to current file
-		if len(self.slicetimes) and self.frameread >= self.slicetimes[0]:
+		if len(self.slicetimes) and self.frameread >= self.slicetimes[0][0]:
 			self.slicetimes.pop(0)
 			# write up to 1st zero crossing
@@ -523,5 +554,5 @@
 			self.fileo = sndfile("%s%s%09.5f%s%s" % 
 				(self.input.split(".")[0].split("/")[-1],".",
-				self.frameread/self.step,".",self.input.split(".")[-1]),model=self.filei)
+				self.frameread*self.params.step,".",self.input.split(".")[-1]),model=self.filei)
 			writesize = self.fileo.write(fromcross,self.mycopy)
 		else:
