Index: examples/aubiomfcc.c
===================================================================
--- examples/aubiomfcc.c	(revision f6ee1606c56bb497f61231d271f40064decbc38f)
+++ examples/aubiomfcc.c	(revision 44e94f3c409560f32cacc692ee02ae88daccd666)
@@ -20,4 +20,5 @@
 
 #include "utils.h"
+#include "parse_args.h"
 
 /* mfcc objects */
Index: examples/aubionotes.c
===================================================================
--- examples/aubionotes.c	(revision f6ee1606c56bb497f61231d271f40064decbc38f)
+++ examples/aubionotes.c	(revision 44e94f3c409560f32cacc692ee02ae88daccd666)
@@ -20,6 +20,8 @@
 
 #define AUBIO_UNSTABLE 1 // for fvec_median
-
 #include "utils.h"
+#define PROG_HAS_PITCH 1
+#define PROG_HAS_ONSET 1
+#include "parse_args.h"
 
 /* pitch objects */
@@ -147,9 +149,9 @@
   examples_common_init(argc,argv);
 
-  o = new_aubio_onset (onset_mode, buffer_size, overlap_size, samplerate);
-  if (threshold != 0.) aubio_onset_set_threshold (o, threshold);
+  o = new_aubio_onset (onset_method, buffer_size, overlap_size, samplerate);
+  if (onset_threshold != 0.) aubio_onset_set_threshold (o, onset_threshold);
   onset = new_fvec (1);
 
-  pitchdet = new_aubio_pitch (pitch_mode, buffer_size * 4,
+  pitchdet = new_aubio_pitch (pitch_method, buffer_size * 4,
           overlap_size, samplerate);
   aubio_pitch_set_tolerance (pitchdet, 0.7);
Index: examples/aubioonset.c
===================================================================
--- examples/aubioonset.c	(revision f6ee1606c56bb497f61231d271f40064decbc38f)
+++ examples/aubioonset.c	(revision 44e94f3c409560f32cacc692ee02ae88daccd666)
@@ -20,4 +20,6 @@
 
 #include "utils.h"
+#define PROG_HAS_ONSET
+#include "parse_args.h"
 
 uint_t pos = 0; /*frames%dspblocksize*/
@@ -69,9 +71,8 @@
 
 int main(int argc, char **argv) {
-  frames_delay = 3;
   examples_common_init(argc,argv);
 
-  o = new_aubio_onset (onset_mode, buffer_size, overlap_size, samplerate);
-  if (threshold != 0.) aubio_onset_set_threshold (o, threshold);
+  o = new_aubio_onset (onset_method, buffer_size, overlap_size, samplerate);
+  if (onset_threshold != 0.) aubio_onset_set_threshold (o, onset_threshold);
   onset = new_fvec (1);
 
Index: examples/aubiopitch.c
===================================================================
--- examples/aubiopitch.c	(revision f6ee1606c56bb497f61231d271f40064decbc38f)
+++ examples/aubiopitch.c	(revision 44e94f3c409560f32cacc692ee02ae88daccd666)
@@ -20,4 +20,6 @@
 
 #include "utils.h"
+#define PROG_HAS_PITCH 1
+#include "parse_args.h"
 
 unsigned int pos = 0; /*frames%dspblocksize*/
@@ -66,5 +68,5 @@
   examples_common_init(argc,argv);
 
-  o = new_aubio_pitch (pitch_mode, buffer_size, overlap_size, samplerate);
+  o = new_aubio_pitch (pitch_method, buffer_size, overlap_size, samplerate);
   pitch = new_fvec (1);
 
Index: examples/aubioquiet.c
===================================================================
--- examples/aubioquiet.c	(revision f6ee1606c56bb497f61231d271f40064decbc38f)
+++ examples/aubioquiet.c	(revision 44e94f3c409560f32cacc692ee02ae88daccd666)
@@ -20,4 +20,5 @@
 
 #include "utils.h"
+#include "parse_args.h"
 
 unsigned int pos = 0; /*frames%dspblocksize*/
Index: examples/aubiotrack.c
===================================================================
--- examples/aubiotrack.c	(revision f6ee1606c56bb497f61231d271f40064decbc38f)
+++ examples/aubiotrack.c	(revision 44e94f3c409560f32cacc692ee02ae88daccd666)
@@ -20,4 +20,6 @@
 
 #include "utils.h"
+#define PROG_HAS_TEMPO 1
+#include "parse_args.h"
 
 uint_t pos = 0;    /* frames%dspblocksize */
@@ -76,6 +78,6 @@
 
   tempo_out = new_fvec(2);
-  bt = new_aubio_tempo(onset_mode,buffer_size,overlap_size, samplerate);
-  if (threshold != 0.) aubio_tempo_set_threshold (bt, threshold);
+  bt = new_aubio_tempo(tempo_method,buffer_size,overlap_size, samplerate);
+  if (onset_threshold != 0.) aubio_tempo_set_threshold (bt, onset_threshold);
 
   wavetable = new_aubio_wavetable (samplerate, overlap_size);
Index: examples/parse_args.h
===================================================================
--- examples/parse_args.h	(revision 44e94f3c409560f32cacc692ee02ae88daccd666)
+++ examples/parse_args.h	(revision 44e94f3c409560f32cacc692ee02ae88daccd666)
@@ -0,0 +1,221 @@
+/*
+  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
+
+  This file is part of aubio.
+
+  aubio is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  aubio is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+extern int verbose;
+// input / output
+extern int usejack;
+extern char_t *source_uri;
+extern char_t *sink_uri;
+// general stuff
+extern uint_t samplerate;
+extern uint_t buffer_size;
+extern uint_t overlap_size;
+// onset stuff
+extern char_t * onset_method;
+extern smpl_t onset_threshold;
+// pitch stuff
+extern char_t * pitch_method;
+extern char_t * pitch_unit;
+extern smpl_t pitch_tolerance;
+// tempo stuff
+extern char_t * tempo_method;
+// more general stuff
+extern smpl_t silence;
+extern uint_t mix_input;
+
+// functions defined in utils.c
+extern void examples_common_init (int argc, char **argv);
+extern void examples_common_del (void);
+extern void examples_common_process (aubio_process_func_t process_func,
+    aubio_print_func_t print);
+
+// internal stuff
+extern int frames;
+
+extern fvec_t *ibuf;
+extern fvec_t *obuf;
+
+
+const char *prog_name;
+
+void
+usage (FILE * stream, int exit_code)
+{
+  fprintf (stream, "usage: %s [ options ] \n", prog_name);
+  fprintf (stream,
+      "       -h      --help             display this message\n"
+      "       -v      --verbose          be verbose\n"
+#ifdef HAVE_JACK
+      "       -j      --jack             use Jack\n"
+#endif
+      "       -i      --input            input type\n"
+      "       -o      --output           output type\n"
+      "       -r      --samplerate       select samplerate\n"
+      "       -B      --bufsize          set buffer size\n"
+      "       -H      --hopsize          set hopsize\n"
+#ifdef PROG_HAS_ONSET
+      "       -O      --onset            select onset detection algorithm\n"
+      "       -t      --onset-threshold  set onset detection threshold\n"
+#endif /* PROG_HAS_ONSET */
+#ifdef PROG_HAS_PITCH
+      "       -p      --pitch            select pitch detection algorithm\n"
+      "       -u      --pitch-unit       select pitch output unit\n"
+      "       -l      --pitch-tolerance  select pitch tolerance\n"
+#endif /* PROG_HAS_PITCH */
+      "       -s      --silence          select silence threshold\n"
+      "       -m      --mix-input        mix input signal with output signal\n"
+      );
+  exit (exit_code);
+}
+
+int
+parse_args (int argc, char **argv)
+{
+  const char *options = "hv"
+#ifdef HAVE_JACK
+    "j"
+#endif
+    "i:o:r:B:H:"
+#ifdef PROG_HAS_ONSET
+    "O:t:"
+#endif /* PROG_HAS_ONSET */
+#ifdef PROG_HAS_PITCH
+    "p:u:l:"
+#endif /* PROG_HAS_PITCH */
+    "s:m";
+  int next_option;
+  struct option long_options[] = {
+    {"help",                  0, NULL, 'h'},
+    {"verbose",               0, NULL, 'v'},
+#ifdef HAVE_JACK
+    {"jack",                  0, NULL, 'j'},
+#endif
+    {"input",                 1, NULL, 'i'},
+    {"output",                1, NULL, 'o'},
+    {"samplerate",            1, NULL, 'r'},
+    {"bufsize",               1, NULL, 'B'},
+    {"hopsize",               1, NULL, 'H'},
+#ifdef PROG_HAS_ONSET
+    {"onset",                 1, NULL, 'O'},
+    {"onset-threshold",       1, NULL, 't'},
+#endif /* PROG_HAS_ONSET */
+#ifdef PROG_HAS_PITCH
+    {"pitch",                 1, NULL, 'p'},
+    {"pitch-unit",            1, NULL, 'u'},
+    {"pitch-tolerance",       1, NULL, 'l'},
+#endif /* PROG_HAS_PITCH */
+    {"silence",               1, NULL, 's'},
+    {"mix-input",             0, NULL, 'm'},
+    {NULL,                    0, NULL, 0}
+  };
+  prog_name = argv[0];
+  if (argc < 1) {
+    usage (stderr, 1);
+    return -1;
+  }
+  do {
+    next_option = getopt_long (argc, argv, options, long_options, NULL);
+    switch (next_option) {
+      case 'h':                /* help */
+        usage (stdout, 0);
+        return -1;
+      case 'v':                /* verbose */
+        verbose = 1;
+        break;
+      case 'j':
+        usejack = 1;
+        break;
+      case 'i':
+        source_uri = optarg;
+        break;
+      case 'o':
+        sink_uri = optarg;
+        break;
+      case 'r':
+        samplerate = atoi (optarg);
+        break;
+      case 'B':
+        buffer_size = atoi (optarg);
+        break;
+      case 'H':
+        overlap_size = atoi (optarg);
+        break;
+      case 'O':                /*onset type */
+        onset_method = optarg;
+        break;
+      case 't':                /* threshold value for onset */
+        onset_threshold = (smpl_t) atof (optarg);
+        break;
+      case 'p':
+        pitch_method = optarg;
+        break;
+      case 'u':
+        pitch_unit = optarg;
+        break;
+      case 'l':
+        pitch_tolerance = (smpl_t) atof (optarg);
+        break;
+      case 's':                /* silence threshold */
+        silence = (smpl_t) atof (optarg);
+        break;
+      case 'm':                /* mix_input flag */
+        mix_input = 1;
+        break;
+      case '?':                /* unknown options */
+        usage (stderr, 1);
+        break;
+      case -1:                 /* done with options */
+        break;
+      default:                 /*something else unexpected */
+        fprintf (stderr, "Error parsing option '%c'\n", next_option);
+        abort ();
+    }
+  }
+  while (next_option != -1);
+
+  if ( source_uri == NULL ) {
+    if (argc - optind == 1) {
+      source_uri = argv[optind];
+    } else if ( argc - optind > 1 ) {
+      errmsg ("Error: too many non-option arguments `%s'\n", argv[argc - 1]);
+      usage ( stderr, 1 );
+    }
+  } else if ( argc - optind > 0 ) {
+    errmsg ("Error: extra non-option argument %s\n", argv[optind]);
+    usage ( stderr, 1 );
+  }
+
+  if (source_uri != NULL) {
+    debug ("Input file : %s\n", source_uri);
+  } else if (source_uri != NULL && sink_uri != NULL) {
+    debug ("Input file : %s\n", source_uri);
+    debug ("Output file : %s\n", sink_uri);
+  } else {
+#if HAVE_JACK
+    debug ("Jack input output\n");
+    usejack = 1;
+#else
+    errmsg("Error: no arguments given (and no available audio input)\n");
+    usage ( stderr, 1 );
+#endif
+  }
+
+  return 0;
+}
Index: examples/utils.c
===================================================================
--- examples/utils.c	(revision f6ee1606c56bb497f61231d271f40064decbc38f)
+++ examples/utils.c	(revision 44e94f3c409560f32cacc692ee02ae88daccd666)
@@ -28,179 +28,44 @@
 
 #include "utils.h"
+#ifdef HAVE_JACK
+#include "jackio.h"
+#endif /* HAVE_JACK */
 
-#ifdef HAVE_LASH
-#include <lash/lash.h>
-#include <pthread.h>
-lash_client_t *aubio_lash_client;
-lash_args_t *lash_args;
-void *lash_thread_main (void *data);
-int lash_main (void);
-void save_data (void);
-void restore_data (lash_config_t * lash_config);
-pthread_t lash_thread;
-#endif /* HAVE_LASH */
+int verbose = 0;
+// input / output
+char_t *sink_uri = NULL;
+char_t *source_uri = NULL;
+// general stuff
+uint_t samplerate = 0;
+uint_t buffer_size = 512;
+uint_t overlap_size = 256;
+// onset stuff
+char_t * onset_method = "default";
+smpl_t onset_threshold = 0.0; // will be set if != 0.
+// pitch stuff
+char_t * pitch_unit = "default";
+char_t * pitch_method = "default";
+smpl_t pitch_tolerance = 0.0; // will be set if != 0.
+// tempo stuff
+char_t * tempo_method = "default";
+// more general stuff
+smpl_t silence = -90.;
+uint_t mix_input = 0;
+
+//
+// internal memory stuff
+aubio_source_t *this_source = NULL;
+aubio_sink_t *this_sink = NULL;
+fvec_t *ibuf;
+fvec_t *obuf;
+
 
 /* settings */
-const char *sink_uri = NULL;
-const char *source_uri = NULL;
 int frames = 0;
-int verbose = 0;
 int usejack = 0;
 int frames_delay = 0;
 
-
-char_t * pitch_unit = "default";
-char_t * pitch_mode = "default";
-
-/* energy,specdiff,hfc,complexdomain,phase */
-char_t * onset_mode = "default";
-smpl_t threshold = 0.0;         // leave unset, only set as asked 
-smpl_t silence = -90.;
-uint_t buffer_size = 512;       //1024;
-uint_t overlap_size = 256;      //512;
-uint_t samplerate = 44100;
-
-aubio_source_t *this_source = NULL;
-aubio_sink_t *this_sink = NULL;
-
-fvec_t *ibuf;
-fvec_t *obuf;
-
-/* badly redeclare some things */
-smpl_t threshold;
-smpl_t averaging;
-const char *prog_name;
-
-void flush_process (aubio_process_func_t process_func,
-    aubio_print_func_t print);
-
-void
-usage (FILE * stream, int exit_code)
-{
-  fprintf (stream, "usage: %s [ options ] \n", prog_name);
-  fprintf (stream,
-      "       -h      --help          Display this message.\n"
-      "       -v      --verbose       Be verbose.\n"
-      "       -j      --jack          Use Jack.\n"
-      "       -o      --output        Output type.\n"
-      "       -i      --input         Input type.\n"
-      "       -O      --onset         Select onset detection algorithm.\n"
-      "       -t      --threshold     Set onset detection threshold.\n"
-      "       -s      --silence       Select silence threshold.\n"
-      "       -p      --pitch         Select pitch detection algorithm.\n"
-      "       -B      --bufsize       Set buffer size.\n"
-      "       -H      --hopsize       Set hopsize.\n"
-      "       -a      --averaging     Use averaging.\n");
-  exit (exit_code);
-}
-
-int
-parse_args (int argc, char **argv)
-{
-  const char *options = "hvjo:i:O:t:s:p:B:H:a";
-  int next_option;
-  struct option long_options[] = {
-    {"help", 0, NULL, 'h'},
-    {"verbose", 0, NULL, 'v'},
-    {"jack", 0, NULL, 'j'},
-    {"output", 1, NULL, 'o'},
-    {"input", 1, NULL, 'i'},
-    {"onset", 1, NULL, 'O'},
-    {"threshold", 1, NULL, 't'},
-    {"silence", 1, NULL, 's'},
-    {"pitch", 1, NULL, 'p'},
-    {"averaging", 0, NULL, 'a'},
-    {"bufsize", 1, NULL, 'B'},
-    {"hopsize", 1, NULL, 'H'},
-    {NULL, 0, NULL, 0}
-  };
-#ifdef HAVE_LASH
-  lash_args = lash_extract_args (&argc, &argv);
-#endif /* HAVE_LASH */
-  prog_name = argv[0];
-  if (argc < 1) {
-    usage (stderr, 1);
-    return -1;
-  }
-  do {
-    next_option = getopt_long (argc, argv, options, long_options, NULL);
-    switch (next_option) {
-      case 'o':
-        sink_uri = optarg;
-        break;
-      case 'i':
-        source_uri = optarg;
-        break;
-      case 'h':                /* help */
-        usage (stdout, 0);
-        return -1;
-      case 'v':                /* verbose */
-        verbose = 1;
-        break;
-      case 'j':
-        usejack = 1;
-        break;
-      case 'O':                /*onset type */
-        onset_mode = optarg;
-        break;
-      case 's':                /* silence value for onset */
-        silence = (smpl_t) atof (optarg);
-        break;
-      case 't':                /* threshold value for onset */
-        threshold = (smpl_t) atof (optarg);
-        break;
-      case 'p':
-        pitch_mode = optarg;
-        break;
-      case 'a':
-        averaging = 1;
-        break;
-      case 'B':
-        buffer_size = atoi (optarg);
-        break;
-      case 'H':
-        overlap_size = atoi (optarg);
-        break;
-      case '?':                /* unknown options */
-        usage (stderr, 1);
-        break;
-      case -1:                 /* done with options */
-        break;
-      default:                 /*something else unexpected */
-        fprintf (stderr, "Error parsing option '%c'\n", next_option);
-        abort ();
-    }
-  }
-  while (next_option != -1);
-
-  if ( source_uri == NULL ) {
-    if (argc - optind == 1) {
-      source_uri = argv[optind];
-    } else if ( argc - optind > 1 ) {
-      errmsg ("Error: too many non-option arguments `%s'\n", argv[argc - 1]);
-      usage ( stderr, 1 );
-    }
-  } else if ( argc - optind > 0 ) {
-    errmsg ("Error: extra non-option argument %s\n", argv[optind]);
-    usage ( stderr, 1 );
-  }
-
-  if (source_uri != NULL) {
-    debug ("Input file : %s\n", source_uri);
-  } else if (source_uri != NULL && sink_uri != NULL) {
-    debug ("Input file : %s\n", source_uri);
-    debug ("Output file : %s\n", sink_uri);
-  } else {
-#if HAVE_JACK
-    debug ("Jack input output\n");
-    usejack = 1;
-#else
-    errmsg("Error: no arguments given (and no available audio input)\n");
-    usage ( stderr, 1 );
-#endif
-  }
-
-  return 0;
-}
+extern void usage (FILE * stream, int exit_code);
+extern int parse_args (int argc, char **argv);
 
 void
@@ -227,22 +92,4 @@
     }
   }
-#ifdef HAVE_LASH
-  else {
-    aubio_lash_client = lash_init (lash_args, argv[0],
-        LASH_Config_Data_Set | LASH_Terminal, LASH_PROTOCOL (2, 0));
-    if (!aubio_lash_client) {
-      fprintf (stderr, "%s: could not initialise lash\n", __FUNCTION__);
-    }
-    /* tell the lash server our client id */
-    if (lash_enabled (aubio_lash_client)) {
-      lash_event_t *event =
-          (lash_event_t *) lash_event_new_with_type (LASH_Client_Name);
-      lash_event_set_string (event, "aubio");
-      lash_send_event (aubio_lash_client, event);
-      pthread_create (&lash_thread, NULL, lash_thread_main, NULL);
-    }
-  }
-#endif /* HAVE_LASH */
-
   ibuf = new_fvec (overlap_size);
   obuf = new_fvec (overlap_size);
@@ -302,19 +149,7 @@
     debug ("Processed %d frames of %d samples.\n", frames, buffer_size);
 
-    flush_process (process_func, print);
     del_aubio_source (this_source);
     del_aubio_sink   (this_sink);
 
-  }
-}
-
-void
-flush_process (aubio_process_func_t process_func, aubio_print_func_t print)
-{
-  uint_t i;
-  fvec_zeros(obuf);
-  for (i = 0; (signed) i < frames_delay; i++) {
-    process_func (&ibuf->data, &obuf->data, overlap_size);
-    print ();
   }
 }
@@ -349,80 +184,2 @@
 }
 
-
-#if HAVE_LASH
-
-void *
-lash_thread_main (void *data __attribute__ ((unused)))
-{
-  printf ("LASH thread running\n");
-
-  while (!lash_main ())
-    usleep (1000);
-
-  printf ("LASH thread finished\n");
-  return NULL;
-}
-
-int
-lash_main (void)
-{
-  lash_event_t *lash_event;
-  lash_config_t *lash_config;
-
-  while ((lash_event = lash_get_event (aubio_lash_client))) {
-    switch (lash_event_get_type (lash_event)) {
-      case LASH_Quit:
-        lash_event_destroy (lash_event);
-        exit (1);
-        return 1;
-      case LASH_Restore_Data_Set:
-        lash_send_event (aubio_lash_client, lash_event);
-        break;
-      case LASH_Save_Data_Set:
-        save_data ();
-        lash_send_event (aubio_lash_client, lash_event);
-        break;
-      case LASH_Server_Lost:
-        return 1;
-      default:
-        printf ("%s: received unknown LASH event of type %d",
-            __FUNCTION__, lash_event_get_type (lash_event));
-        lash_event_destroy (lash_event);
-        break;
-    }
-  }
-
-  while ((lash_config = lash_get_config (aubio_lash_client))) {
-    restore_data (lash_config);
-    lash_config_destroy (lash_config);
-  }
-
-  return 0;
-}
-
-void
-save_data ()
-{
-  lash_config_t *lash_config;
-
-  lash_config = lash_config_new_with_key ("threshold");
-  lash_config_set_value_double (lash_config, threshold);
-  lash_send_config (aubio_lash_client, lash_config);
-
-}
-
-void
-restore_data (lash_config_t * lash_config)
-{
-  const char *lash_key;
-
-  lash_key = lash_config_get_key (lash_config);
-
-  if (strcmp (lash_key, "threshold") == 0) {
-    threshold = lash_config_get_value_double (lash_config);
-    return;
-  }
-
-}
-
-#endif /* HAVE_LASH */
Index: examples/utils.h
===================================================================
--- examples/utils.h	(revision f6ee1606c56bb497f61231d271f40064decbc38f)
+++ examples/utils.h	(revision 44e94f3c409560f32cacc692ee02ae88daccd666)
@@ -28,7 +28,4 @@
 #include <aubio.h>
 #include "config.h"
-#ifdef HAVE_JACK
-#include "jackio.h"
-#endif /* HAVE_JACK */
 
 #ifdef HAVE_C99_VARARGS_MACROS
@@ -42,14 +39,4 @@
 #endif
 
-
-extern int frames;
-extern int verbose;
-extern int usejack;
-extern int frames_delay;
-/* defined in utils.c */
-void usage (FILE * stream, int exit_code);
-int parse_args (int argc, char **argv);
-void examples_common_init (int argc, char **argv);
-void examples_common_del (void);
 typedef void (aubio_print_func_t) (void);
 #ifndef HAVE_JACK
@@ -57,22 +44,5 @@
   (smpl_t ** input, smpl_t ** output, int nframes);
 #endif
-void examples_common_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);
 
-extern const char *sink_uri;
-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;
-extern uint_t samplerate;
 
-extern fvec_t *ibuf;
-extern fvec_t *obuf;
