Index: examples/aubiomfcc.c
===================================================================
--- examples/aubiomfcc.c	(revision 2828382225dfbf3ac6e5cc5ef745c18845a0ee53)
+++ examples/aubiomfcc.c	(revision d4c5de7b1235d18d93df4de76c2e1e88e7e3d03c)
@@ -23,4 +23,6 @@
 fvec_t * mfcc_out;
 aubio_mfcc_t * mfcc;
+aubio_pvoc_t *pv;
+cvec_t *fftgrain;
 
 uint_t n_filters = 40;
@@ -28,8 +30,6 @@
 
 unsigned int pos = 0; /*frames%dspblocksize*/
-uint_t usepitch = 0;
 
-int aubio_process(smpl_t **input, smpl_t **output, int nframes);
-int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
+static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
   unsigned int i;       /*channels*/
   unsigned int j;       /*frames*/
@@ -62,6 +62,5 @@
 }
 
-void process_print (void);
-void process_print (void) {
+static void process_print (void) {
       /* output times in seconds
          write extracted mfccs
@@ -84,9 +83,14 @@
   
   examples_common_init(argc,argv);
+
+  /* phase vocoder */
+  pv = new_aubio_pvoc (buffer_size, overlap_size, channels);
+
+  fftgrain = new_cvec (buffer_size, channels);
+
+  //populating the filter
+  mfcc = new_aubio_mfcc(buffer_size, n_filters, n_coefs, samplerate);
+  
   mfcc_out = new_fvec(n_coefs,channels);
-  
-  
-  //populating the filter
-  mfcc = new_aubio_mfcc(buffer_size, samplerate, n_filters, n_coefs);
   
   //process
@@ -94,4 +98,6 @@
   
   //destroying mfcc 
+  del_aubio_pvoc (pv);
+  del_cvec (fftgrain);
   del_aubio_mfcc(mfcc);
   del_fvec(mfcc_out);
Index: examples/aubionotes.c
===================================================================
--- examples/aubionotes.c	(revision 2828382225dfbf3ac6e5cc5ef745c18845a0ee53)
+++ examples/aubionotes.c	(revision d4c5de7b1235d18d93df4de76c2e1e88e7e3d03c)
@@ -19,9 +19,31 @@
 #include "utils.h"
 
+/* pitch objects */
+smpl_t pitch = 0.;
+
+uint_t median = 6;
+smpl_t curlevel = 0.;
+
+aubio_pitchdetection_t *pitchdet;
+
+fvec_t *note_buffer = NULL;
+fvec_t *note_buffer2 = NULL;
+
+smpl_t curnote = 0.;
+smpl_t newnote = 0.;
+uint_t isready = 0;
 unsigned int pos = 0; /*frames%dspblocksize*/
-uint_t usepitch = 1;
 
-int aubio_process(smpl_t **input, smpl_t **output, int nframes);
-int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
+aubio_pitchdetection_t *pitchdet;
+aubio_onset_t *o;
+fvec_t *onset;
+fvec_t *pitch_obuf;
+
+/** append new note candidate to the note_buffer and return filtered value. we
+ * need to copy the input array as fvec_median destroy its input data.*/
+void note_append (fvec_t * note_buffer, smpl_t curnote);
+uint_t get_note (fvec_t * note_buffer, fvec_t * note_buffer2);
+
+static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
   unsigned int i;       /*channels*/
   unsigned int j;       /*frames*/
@@ -38,7 +60,5 @@
     if (pos == overlap_size-1) {         
       /* block loop */
-      aubio_pvoc_do (pv,ibuf, fftgrain);
-      aubio_onsetdetection_do(o,fftgrain, onset);
-      isonset = aubio_peakpicker_do(parms, onset);
+      aubio_onset_do(o, ibuf, onset);
       
       aubio_pitchdetection_do (pitchdet, ibuf, pitch_obuf);
@@ -50,8 +70,7 @@
       /* curlevel is negatif or 1 if silence */
       curlevel = aubio_level_detection(ibuf, silence);
-      if (isonset) {
+      if (fvec_read_sample(onset, 0, 0)) {
               /* test for silence */
               if (curlevel == 1.) {
-                      isonset=0;
                       if (median) isready = 0;
                       /* send note off */
@@ -99,12 +118,55 @@
 }
 
-void process_print (void);
-void process_print (void) {
+static void process_print (void) {
       if (verbose) outmsg("%f\n",pitch);
+}
+
+void
+note_append (fvec_t * note_buffer, smpl_t curnote)
+{
+  uint_t i = 0;
+  for (i = 0; i < note_buffer->length - 1; i++) {
+    note_buffer->data[0][i] = note_buffer->data[0][i + 1];
+  }
+  note_buffer->data[0][note_buffer->length - 1] = curnote;
+  return;
+}
+
+uint_t
+get_note (fvec_t * note_buffer, fvec_t * note_buffer2)
+{
+  uint_t i = 0;
+  for (i = 0; i < note_buffer->length; i++) {
+    note_buffer2->data[0][i] = note_buffer->data[0][i];
+  }
+  return fvec_median (note_buffer2);
 }
 
 int main(int argc, char **argv) {
   examples_common_init(argc,argv);
+
+  o = new_aubio_onset (onset_mode, buffer_size, overlap_size, channels,
+          samplerate);
+  onset = new_fvec (1, channels);
+
+  pitchdet = new_aubio_pitchdetection (pitch_mode, buffer_size * 4,
+          overlap_size, channels, samplerate);
+  aubio_pitchdetection_set_tolerance (pitchdet, 0.7);
+  pitch_obuf = new_fvec (1, channels);
+  if (median) {
+      note_buffer = new_fvec (median, 1);
+      note_buffer2 = new_fvec (median, 1);
+  }
+
   examples_common_process(aubio_process, process_print);
+
+  send_noteon (curnote, 0);
+  del_aubio_pitchdetection (pitchdet);
+  if (median) {
+      del_fvec (note_buffer);
+      del_fvec (note_buffer2);
+  }
+  del_fvec (pitch_obuf);
+
   examples_common_del();
   debug("End of program.\n");
Index: examples/aubioonset.c
===================================================================
--- examples/aubioonset.c	(revision 2828382225dfbf3ac6e5cc5ef745c18845a0ee53)
+++ examples/aubioonset.c	(revision d4c5de7b1235d18d93df4de76c2e1e88e7e3d03c)
@@ -20,8 +20,9 @@
 
 unsigned int pos = 0; /*frames%dspblocksize*/
-uint_t usepitch = 0;
 
-int aubio_process(smpl_t **input, smpl_t **output, int nframes);
-int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
+aubio_onset_t *o;
+fvec_t *onset;
+
+static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
   unsigned int i;       /*channels*/
   unsigned int j;       /*frames*/
@@ -38,18 +39,13 @@
     if (pos == overlap_size-1) {         
       /* block loop */
-      aubio_pvoc_do (pv,ibuf, fftgrain);
-      aubio_onsetdetection_do (o,fftgrain, onset);
-      isonset = aubio_peakpicker_do(parms, onset);
-      if (isonset) {
-        /* test for silence */
-        if (aubio_silence_detection(ibuf, silence)==1)
-          isonset=0.;
-        else
-          for (pos = 0; pos < overlap_size; pos++){
-            obuf->data[0][pos] = woodblock->data[0][pos];
-          }
+      aubio_onset_do (o, ibuf, onset);
+      if (fvec_read_sample(onset, 0, 0)) {
+        for (pos = 0; pos < overlap_size; pos++){
+          obuf->data[0][pos] = woodblock->data[0][pos];
+        }
       } else {
-        for (pos = 0; pos < overlap_size; pos++)
+        for (pos = 0; pos < overlap_size; pos++) {
           obuf->data[0][pos] = 0.;
+        }
       }
       /* end of block loop */
@@ -61,12 +57,14 @@
 }
 
-void process_print (void);
-void process_print (void) {
+static void process_print (void) {
       /* output times in seconds, taking back some 
        * delay to ensure the label is _before_ the
        * actual onset */
-      if (isonset && output_filename == NULL) {
+      if (!verbose && usejack) return;
+      smpl_t onset_found = fvec_read_sample(onset, 0, 0);
+      if (onset_found) {
         if(frames >= 4) {
-          outmsg("%f\n",(frames - frames_delay + isonset)*overlap_size/(float)samplerate);
+          outmsg("%f\n",(frames - frames_delay + onset_found) 
+                  *overlap_size/(float)samplerate);
         } else if (frames < frames_delay) {
           outmsg("%f\n",0.);
@@ -78,5 +76,14 @@
   frames_delay = 3;
   examples_common_init(argc,argv);
+
+  o = new_aubio_onset (onset_mode, buffer_size, overlap_size, channels,
+          samplerate);
+  onset = new_fvec (1, channels);
+
   examples_common_process(aubio_process,process_print);
+
+  del_aubio_onset (o);
+  del_fvec (onset);
+
   examples_common_del();
   debug("End of program.\n");
Index: examples/aubioquiet.c
===================================================================
--- examples/aubioquiet.c	(revision 2828382225dfbf3ac6e5cc5ef745c18845a0ee53)
+++ examples/aubioquiet.c	(revision d4c5de7b1235d18d93df4de76c2e1e88e7e3d03c)
@@ -21,5 +21,4 @@
 unsigned int pos = 0; /*frames%dspblocksize*/
 sint_t wassilence = 1, issilence;
-uint_t usepitch = 0;
 
 int aubio_process(smpl_t **input, smpl_t **output, int nframes);
@@ -56,6 +55,5 @@
 }
 
-void process_print (void);
-void process_print (void) {
+static void process_print (void) {
       int curframes = (frames - 4) > 0 ? frames -4 : 0;
       if (issilence == -1) {
Index: examples/aubiotrack.c
===================================================================
--- examples/aubiotrack.c	(revision 2828382225dfbf3ac6e5cc5ef745c18845a0ee53)
+++ examples/aubiotrack.c	(revision d4c5de7b1235d18d93df4de76c2e1e88e7e3d03c)
@@ -20,12 +20,11 @@
 #include "utils.h"
 
-unsigned int pos          = 0;    /* frames%dspblocksize */
-uint_t usepitch           = 0;
-fvec_t * out              = NULL;
-aubio_tempo_t * bt        = NULL;
-smpl_t istactus           = 0;
+uint_t pos = 0;    /* frames%dspblocksize */
+fvec_t * tempo_out = NULL;
+aubio_tempo_t * bt = NULL;
+smpl_t istactus = 0;
+smpl_t isonset = 0;
 
-int aubio_process(smpl_t **input, smpl_t **output, int nframes);
-int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
+static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
   unsigned int i;       /*channels*/
   unsigned int j;       /*frames*/
@@ -42,9 +41,13 @@
     if (pos == overlap_size-1) {         
       /* block loop */
-      aubio_tempo_do (bt,ibuf,out);
-      if (out->data[0][0]>=1) 
-        istactus = out->data[0][0];
+      aubio_tempo_do (bt,ibuf,tempo_out);
+      if (tempo_out->data[0][0]>0) 
+        istactus = tempo_out->data[0][0];
       else 
         istactus = 0;
+      if (tempo_out->data[0][1]>0) 
+        isonset = tempo_out->data[0][0];
+      else 
+        isonset = 0;
       if (istactus) {
               for (pos = 0; pos < overlap_size; pos++)
@@ -62,6 +65,5 @@
 }
 
-void process_print (void);
-void process_print (void) {
+static void process_print (void) {
         if (output_filename == NULL) {
                 if (istactus) {
@@ -80,11 +82,11 @@
   examples_common_init(argc,argv);
 
-  out = new_fvec(2,channels);
-  bt  = new_aubio_tempo(onset_mode,buffer_size,overlap_size,channels);
+  tempo_out = new_fvec(2,channels);
+  bt = new_aubio_tempo(onset_mode,buffer_size,overlap_size,channels, samplerate);
 
   examples_common_process(aubio_process,process_print);
 
   del_aubio_tempo(bt);
-  del_fvec(out);
+  del_fvec(tempo_out);
 
   examples_common_del();
Index: examples/utils.c
===================================================================
--- examples/utils.c	(revision 2828382225dfbf3ac6e5cc5ef745c18845a0ee53)
+++ examples/utils.c	(revision d4c5de7b1235d18d93df4de76c2e1e88e7e3d03c)
@@ -16,4 +16,12 @@
   You should have received a copy of the GNU General Public License
   along with aubio.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+/** 
+
+  This file includes some tools common to all examples. Code specific to the
+  algorithm performed by each program should go in the source file of that
+  program instead.
 
 */
@@ -41,7 +49,9 @@
 int verbose = 0;
 int usejack = 0;
-int usedoubled = 1;
 int frames_delay = 0;
 
+
+char_t * pitch_unit = "default";
+char_t * pitch_mode = "default";
 
 /* energy,specdiff,hfc,complexdomain,phase */
@@ -58,34 +68,7 @@
 aubio_sndfile_t *fileout = NULL;
 
-aubio_pvoc_t *pv;
 fvec_t *ibuf;
 fvec_t *obuf;
-fvec_t *pitch_obuf;
-cvec_t *fftgrain;
 fvec_t *woodblock;
-aubio_onsetdetection_t *o;
-fvec_t *onset;
-fvec_t *onset2;
-smpl_t isonset = 0;
-aubio_peakpicker_t *parms;
-
-
-/* pitch objects */
-smpl_t pitch = 0.;
-aubio_pitchdetection_t *pitchdet;
-char_t * pitch_unit = "default";
-char_t * pitch_mode = "default";
-uint_t median = 6;
-
-fvec_t *note_buffer = NULL;
-fvec_t *note_buffer2 = NULL;
-smpl_t curlevel = 0.;
-smpl_t maxonset = 0.;
-
-smpl_t curnote = 0.;
-smpl_t newnote = 0.;
-uint_t isready = 0;
-
-
 
 /* badly redeclare some things */
@@ -93,4 +76,7 @@
 smpl_t averaging;
 const char *prog_name;
+
+void flush_process (aubio_process_func_t process_func,
+    aubio_print_func_t print);
 
 void
@@ -222,4 +208,5 @@
 {
 
+  uint_t found_wood = 0;
 
   aubio_sndfile_t *onsetfile = NULL;
@@ -230,5 +217,5 @@
   if (output_filename || usejack) {
     /* dummy assignement to keep egcs happy */
-    isonset = (onsetfile = new_aubio_sndfile_ro (onset_filename)) ||
+    found_wood = (onsetfile = new_aubio_sndfile_ro (onset_filename)) ||
         (onsetfile = new_aubio_sndfile_ro ("sounds/woodblock.aiff")) ||
         (onsetfile = new_aubio_sndfile_ro ("../sounds/woodblock.aiff"));
@@ -277,23 +264,4 @@
   ibuf = new_fvec (overlap_size, channels);
   obuf = new_fvec (overlap_size, channels);
-  fftgrain = new_cvec (buffer_size, channels);
-
-  if (usepitch) {
-    pitchdet = new_aubio_pitchdetection (pitch_mode, buffer_size * 4,
-        overlap_size, channels, samplerate);
-    aubio_pitchdetection_set_tolerance (pitchdet, 0.7);
-    pitch_obuf = new_fvec (1, channels);
-
-    if (median) {
-      note_buffer = new_fvec (median, 1);
-      note_buffer2 = new_fvec (median, 1);
-    }
-  }
-  /* phase vocoder */
-  pv = new_aubio_pvoc (buffer_size, overlap_size, channels);
-  /* onsets */
-  parms = new_aubio_peakpicker (threshold);
-  o = new_aubio_onsetdetection (onset_mode, buffer_size, channels);
-  onset = new_fvec (1, channels);
 
 }
@@ -303,20 +271,6 @@
 examples_common_del (void)
 {
-  if (usepitch) {
-    send_noteon (curnote, 0);
-    del_aubio_pitchdetection (pitchdet);
-    if (median) {
-      del_fvec (note_buffer);
-      del_fvec (note_buffer2);
-    }
-    del_fvec (pitch_obuf);
-  }
-  del_aubio_onsetdetection (o);
-  del_aubio_peakpicker (parms);
-  del_aubio_pvoc (pv);
+  del_fvec (ibuf);
   del_fvec (obuf);
-  del_fvec (ibuf);
-  del_cvec (fftgrain);
-  del_fvec (onset);
   del_fvec (woodblock);
   aubio_cleanup ();
@@ -355,5 +309,4 @@
     while ((signed) overlap_size == aubio_sndfile_read (file, overlap_size,
             ibuf)) {
-      isonset = 0;
       process_func (ibuf->data, obuf->data, overlap_size);
       print ();
@@ -416,25 +369,4 @@
 
 
-void
-note_append (fvec_t * note_buffer, smpl_t curnote)
-{
-  uint_t i = 0;
-  for (i = 0; i < note_buffer->length - 1; i++) {
-    note_buffer->data[0][i] = note_buffer->data[0][i + 1];
-  }
-  note_buffer->data[0][note_buffer->length - 1] = curnote;
-  return;
-}
-
-uint_t
-get_note (fvec_t * note_buffer, fvec_t * note_buffer2)
-{
-  uint_t i = 0;
-  for (i = 0; i < note_buffer->length; i++) {
-    note_buffer2->data[0][i] = note_buffer->data[0][i];
-  }
-  return fvec_median (note_buffer2);
-}
-
 #if HAVE_LASH
 
Index: examples/utils.h
===================================================================
--- examples/utils.h	(revision 2828382225dfbf3ac6e5cc5ef745c18845a0ee53)
+++ examples/utils.h	(revision d4c5de7b1235d18d93df4de76c2e1e88e7e3d03c)
@@ -43,9 +43,5 @@
 extern int verbose;
 extern int usejack;
-extern int usedoubled;
 extern int frames_delay;
-extern unsigned int median;
-extern const char *output_filename;
-extern const char *input_filename;
 /* defined in utils.c */
 void usage (FILE * stream, int exit_code);
@@ -60,26 +56,16 @@
 void examples_common_process (aubio_process_func_t process_func,
     aubio_print_func_t print);
-void flush_process (aubio_process_func_t process_func,
-    aubio_print_func_t print);
 
+extern char_t * pitch_unit;
+extern char_t * pitch_mode;
 
 void send_noteon (int pitch, int velo);
-/** append new note candidate to the note_buffer and return filtered value. we
- * need to copy the input array as fvec_median destroy its input data.*/
-void note_append (fvec_t * note_buffer, smpl_t curnote);
-uint_t get_note (fvec_t * note_buffer, fvec_t * note_buffer2);
 
 extern const char *output_filename;
-extern const char *input_filename;
-extern const char *onset_filename;
-extern int verbose;
-extern int usejack;
-extern int usedoubled;
-
-
-/* energy,specdiff,hfc,complexdomain,phase */
 extern char_t * onset_mode;
 extern smpl_t threshold;
 extern smpl_t silence;
+extern int verbose;
+extern int usejack;
 extern uint_t buffer_size;
 extern uint_t overlap_size;
@@ -87,36 +73,5 @@
 extern uint_t samplerate;
 
-
-extern aubio_sndfile_t *file;
-extern aubio_sndfile_t *fileout;
-
-extern aubio_pvoc_t *pv;
 extern fvec_t *ibuf;
 extern fvec_t *obuf;
-extern fvec_t *pitch_obuf;
-extern cvec_t *fftgrain;
 extern fvec_t *woodblock;
-extern aubio_onsetdetection_t *o;
-extern aubio_onsetdetection_t *o2;
-extern fvec_t *onset;
-extern fvec_t *onset2;
-extern smpl_t isonset;
-extern aubio_peakpicker_t *parms;
-
-
-/* pitch objects */
-extern smpl_t pitch;
-extern aubio_pitchdetection_t *pitchdet;
-extern uint_t median;
-
-extern fvec_t *note_buffer;
-extern fvec_t *note_buffer2;
-extern smpl_t curlevel;
-extern smpl_t maxonset;
-
-extern smpl_t curnote;
-extern smpl_t newnote;
-extern uint_t isready;
-
-/* per example param */
-extern uint_t usepitch;
