Index: src/onset/onset.c
===================================================================
--- src/onset/onset.c	(revision e4f142c3109be03c707aec0081c4008f2b5813e8)
+++ src/onset/onset.c	(revision 56ef7e1e2d47981012ffa6f5fa94691d90729ffa)
@@ -37,5 +37,5 @@
   smpl_t silence;               /**< silence threhsold */
   uint_t minioi;                /**< minimum inter onset interval */
-  uint_t wasonset;              /**< number of frames since last onset */
+  fvec_t * wasonset;            /**< number of frames since last onset */
   uint_t samplerate;            /**< sampling rate of the input signal */
 };
@@ -44,6 +44,7 @@
 void aubio_onset_do (aubio_onset_t *o, fvec_t * input, fvec_t * onset)
 {
-  uint_t isonset = 0;
-  uint_t wasonset = o->wasonset;
+  smpl_t isonset = 0;
+  smpl_t wasonset = 0;
+  uint_t i;
   aubio_pvoc_do (o->pv,input, o->fftgrain);
   aubio_onsetdetection_do (o->od,o->fftgrain, o->of);
@@ -52,5 +53,8 @@
     onset->data[0][0] *= onset2->data[0][0];
   }*/
-  isonset = aubio_peakpicker_do(o->pp, o->of);
+  aubio_peakpicker_do(o->pp, o->of, onset);
+  for (i = 0; i < input->channels; i++) {
+  isonset = onset->data[i][0];
+  wasonset = o->wasonset->data[i][0];
   if (isonset > 0.) {
     if (aubio_silence_detection(input, o->silence)==1) {
@@ -68,6 +72,7 @@
     wasonset++;
   }
-  o->wasonset = wasonset;
-  onset->data[0][0] = isonset;
+  o->wasonset->data[i][0] = wasonset;
+  onset->data[i][0] = isonset;
+  }
   return;
 }
@@ -98,8 +103,9 @@
   o->minioi    = 4;
   o->silence   = -70;
-  o->wasonset  = 0;
+  o->wasonset  = new_fvec(1, channels);
   o->samplerate = samplerate;
   o->pv = new_aubio_pvoc(buf_size, hop_size, channels);
-  o->pp = new_aubio_peakpicker(o->threshold);
+  o->pp = new_aubio_peakpicker(channels);
+  aubio_peakpicker_set_threshold (o->pp, o->threshold);
   o->od = new_aubio_onsetdetection(onset_mode,buf_size,channels);
   o->fftgrain = new_cvec(buf_size,channels);
@@ -118,4 +124,5 @@
   del_aubio_pvoc(o->pv);
   del_fvec(o->of);
+  del_fvec(o->wasonset);
   del_cvec(o->fftgrain);
   AUBIO_FREE(o);
Index: src/onset/peakpick.c
===================================================================
--- src/onset/peakpick.c	(revision e4f142c3109be03c707aec0081c4008f2b5813e8)
+++ src/onset/peakpick.c	(revision 56ef7e1e2d47981012ffa6f5fa94691d90729ffa)
@@ -53,4 +53,7 @@
 	fvec_t * scratch;
 
+  /** number of channels to analyse */
+  uint_t channels;
+
 	/** \bug should be used to calculate filter coefficients */
 	/* cutoff: low-pass filter cutoff [0.34, 1] */
@@ -68,52 +71,49 @@
  * is slightly more permissive than the offline one, and yelds to an increase
  * of false positives. best  */
-smpl_t aubio_peakpicker_do(aubio_peakpicker_t * p, fvec_t * onset) {
-	fvec_t * onset_keep = (fvec_t *)p->onset_keep;
-	fvec_t * onset_proc = (fvec_t *)p->onset_proc;
-	fvec_t * onset_peek = (fvec_t *)p->onset_peek;
-	fvec_t * scratch    = (fvec_t *)p->scratch;
-	smpl_t mean = 0., median = 0.;
-  smpl_t isonset = 0.;
-	uint_t length = p->win_post + p->win_pre + 1;
-	uint_t i = 0, j;
+void
+aubio_peakpicker_do (aubio_peakpicker_t * p, fvec_t * onset, fvec_t * out)
+{
+  fvec_t *onset_keep = p->onset_keep;
+  fvec_t *onset_proc = p->onset_proc;
+  fvec_t *onset_peek = p->onset_peek;
+  fvec_t *scratch = p->scratch;
+  smpl_t mean = 0., median = 0.;
+  uint_t length = p->win_post + p->win_pre + 1;
+  uint_t i, j = 0;
 
-	/* store onset in onset_keep */
-	/* shift all elements but last, then write last */
-	/* for (i=0;i<channels;i++) { */
-	for (j=0;j<length-1;j++) {
-		onset_keep->data[i][j] = onset_keep->data[i][j+1];
-		onset_proc->data[i][j] = onset_keep->data[i][j];
-	}
-	onset_keep->data[i][length-1] = onset->data[i][0];
-	onset_proc->data[i][length-1] = onset->data[i][0];
-	/* } */
+  for (i = 0; i < p->channels; i++) {
+    /* store onset in onset_keep */
+    /* shift all elements but last, then write last */
+    for (j = 0; j < length - 1; j++) {
+      onset_keep->data[i][j] = onset_keep->data[i][j + 1];
+      onset_proc->data[i][j] = onset_keep->data[i][j];
+    }
+    onset_keep->data[i][length - 1] = onset->data[i][0];
+    onset_proc->data[i][length - 1] = onset->data[i][0];
+  }
 
-	/* filter onset_proc */
-	/** \bug filtfilt calculated post+pre times, should be only once !? */
-	aubio_biquad_do_filtfilt(p->biquad,onset_proc,scratch);
+  /* filter onset_proc */
+  /** \bug filtfilt calculated post+pre times, should be only once !? */
+  //aubio_biquad_do_filtfilt(p->biquad,onset_proc,scratch);
 
-	/* calculate mean and median for onset_proc */
-	/* for (i=0;i<onset_proc->channels;i++) { */
-	mean = fvec_mean(onset_proc);
-	/* copy to scratch */
-	for (j = 0; j < length; j++)
-		scratch->data[i][j] = onset_proc->data[i][j];
-	median = p->thresholdfn(scratch);
-	/* } */
+  for (i = 0; i < p->channels; i++) {
+    /* calculate mean and median for onset_proc */
+    mean = fvec_mean_channel (onset_proc, i);
+    /* copy to scratch */
+    for (j = 0; j < length; j++)
+      scratch->data[i][j] = onset_proc->data[i][j];
+    median = p->thresholdfn (scratch, i);
 
-	/* for (i=0;i<onset->channels;i++) { */
-	/* shift peek array */
-	for (j=0;j<3-1;j++) 
-		onset_peek->data[i][j] = onset_peek->data[i][j+1];
-	/* calculate new peek value */
-	onset_peek->data[i][2] = 
-		onset_proc->data[i][p->win_post] - median - mean * p->threshold;
-	/* } */
-	//AUBIO_DBG("%f\n", onset_peek->data[0][2]);
-  isonset = (p->pickerfn)(onset_peek,1);
-  if (isonset) { //(isonset) {
-    isonset = fvec_quadint(onset_peek, 1, 1);
+    /* shift peek array */
+    for (j = 0; j < 3 - 1; j++)
+      onset_peek->data[i][j] = onset_peek->data[i][j + 1];
+    /* calculate new peek value */
+    onset_peek->data[i][2] =
+        onset_proc->data[i][p->win_post] - median - mean * p->threshold;
+    out->data[i][0] = (p->pickerfn) (onset_peek, 1);
+    if (out->data[i][0]) {
+      out->data[i][0] = fvec_quadint (onset_peek, 1, i);
+    }
   }
-	return isonset;
 }
 
@@ -126,7 +126,6 @@
 }
 
-/** function added by Miguel Ramirez to return the onset detection amplitude in peakval */
 uint_t aubio_peakpicker_set_threshold(aubio_peakpicker_t * p, smpl_t threshold) {
-	p->threshold = threshold;
+    p->threshold = threshold;
 	return AUBIO_OK;
 }
@@ -145,19 +144,19 @@
 }
 
-aubio_peakpicker_t * new_aubio_peakpicker(smpl_t threshold) {
+aubio_peakpicker_t * new_aubio_peakpicker(uint_t channels) {
 	aubio_peakpicker_t * t = AUBIO_NEW(aubio_peakpicker_t);
 	t->threshold = 0.1; /* 0.0668; 0.33; 0.082; 0.033; */
-	if (threshold > 0. && threshold < 10.)
-		t->threshold = threshold;
 	t->win_post  = 5;
 	t->win_pre   = 1;
+  //channels = 1;
+  t->channels = channels;
 
-	t->thresholdfn = (aubio_thresholdfn_t)(fvec_median); /* (fvec_mean); */
+	t->thresholdfn = (aubio_thresholdfn_t)(fvec_median_channel); /* (fvec_mean); */
 	t->pickerfn = (aubio_pickerfn_t)(fvec_peakpick);
 
-	t->scratch = new_fvec(t->win_post+t->win_pre+1,1);
-	t->onset_keep = new_fvec(t->win_post+t->win_pre+1,1);
-	t->onset_proc = new_fvec(t->win_post+t->win_pre+1,1);
-	t->onset_peek = new_fvec(3,1);
+	t->scratch = new_fvec(t->win_post+t->win_pre+1, channels);
+	t->onset_keep = new_fvec(t->win_post+t->win_pre+1, channels);
+	t->onset_proc = new_fvec(t->win_post+t->win_pre+1, channels);
+	t->onset_peek = new_fvec(3, channels);
 
 	/* cutoff: low-pass filter cutoff [0.34, 1] */
Index: src/onset/peakpick.h
===================================================================
--- src/onset/peakpick.h	(revision e4f142c3109be03c707aec0081c4008f2b5813e8)
+++ src/onset/peakpick.h	(revision 56ef7e1e2d47981012ffa6f5fa94691d90729ffa)
@@ -32,5 +32,5 @@
 
 /** function pointer to thresholding function */
-typedef smpl_t (*aubio_thresholdfn_t)(fvec_t *input);
+typedef smpl_t (*aubio_thresholdfn_t)(fvec_t *input, uint_t channel);
 /** function pointer to peak-picking function */
 typedef uint_t (*aubio_pickerfn_t)(fvec_t *input, uint_t pos);
@@ -39,7 +39,7 @@
 
 /** peak-picker creation function */
-aubio_peakpicker_t * new_aubio_peakpicker(smpl_t threshold);
+aubio_peakpicker_t * new_aubio_peakpicker(uint_t channels);
 /** real time peak picking function */
-smpl_t aubio_peakpicker_do(aubio_peakpicker_t * p, fvec_t * DF);
+void aubio_peakpicker_do(aubio_peakpicker_t * p, fvec_t * in, fvec_t * out);
 /** get current peak value */
 smpl_t aubio_peakpicker_get_thresholded_input(aubio_peakpicker_t * p);
