Index: examples/aubioonset.c
===================================================================
--- examples/aubioonset.c	(revision a24a84ef787217ef02c81c99363f1c6aadb3f34b)
+++ examples/aubioonset.c	(revision 1239d230255db345d182047be6736c0c884343b8)
@@ -44,8 +44,10 @@
     aubio_wavetable_stop ( wavetable );
   }
-  if (mix_input)
+  if (mix_input) {
     aubio_wavetable_do (wavetable, ibuf, obuf);
-  else
+    fvec_clamp(obuf, 1.);
+  } else {
     aubio_wavetable_do (wavetable, obuf, obuf);
+  }
 }
 
Index: examples/aubiotrack.c
===================================================================
--- examples/aubiotrack.c	(revision a24a84ef787217ef02c81c99363f1c6aadb3f34b)
+++ examples/aubiotrack.c	(revision 1239d230255db345d182047be6736c0c884343b8)
@@ -47,8 +47,10 @@
     aubio_wavetable_stop ( wavetable );
   }
-  if (mix_input)
+  if (mix_input) {
     aubio_wavetable_do (wavetable, ibuf, obuf);
-  else
+    fvec_clamp(obuf, 1.);
+  } else {
     aubio_wavetable_do (wavetable, obuf, obuf);
+  }
 }
 
Index: python/lib/gen_code.py
===================================================================
--- python/lib/gen_code.py	(revision a24a84ef787217ef02c81c99363f1c6aadb3f34b)
+++ python/lib/gen_code.py	(revision 1239d230255db345d182047be6736c0c884343b8)
@@ -184,15 +184,19 @@
     def gen_code(self):
         out = ""
-        out += self.gen_struct()
-        out += self.gen_doc()
-        out += self.gen_new()
-        out += self.gen_init()
-        out += self.gen_del()
-        out += self.gen_do()
-        out += self.gen_memberdef()
-        out += self.gen_set()
-        out += self.gen_get()
-        out += self.gen_methodef()
-        out += self.gen_typeobject()
+        try:
+            out += self.gen_struct()
+            out += self.gen_doc()
+            out += self.gen_new()
+            out += self.gen_init()
+            out += self.gen_del()
+            out += self.gen_do()
+            out += self.gen_memberdef()
+            out += self.gen_set()
+            out += self.gen_get()
+            out += self.gen_methodef()
+            out += self.gen_typeobject()
+        except Exception as e:
+            print ("Failed generating code for", self.shortname)
+            raise
         return out
 
Index: python/lib/gen_external.py
===================================================================
--- python/lib/gen_external.py	(revision a24a84ef787217ef02c81c99363f1c6aadb3f34b)
+++ python/lib/gen_external.py	(revision 1239d230255db345d182047be6736c0c884343b8)
@@ -40,4 +40,5 @@
   #'sampler',
   'audio_unit',
+  'spectral_whitening',
   ]
 
Index: src/aubio.h
===================================================================
--- src/aubio.h	(revision a24a84ef787217ef02c81c99363f1c6aadb3f34b)
+++ src/aubio.h	(revision 1239d230255db345d182047be6736c0c884343b8)
@@ -188,4 +188,5 @@
 #include "spectral/mfcc.h"
 #include "spectral/specdesc.h"
+#include "spectral/awhitening.h"
 #include "spectral/tss.h"
 #include "pitch/pitch.h"
Index: src/cvec.c
===================================================================
--- src/cvec.c	(revision a24a84ef787217ef02c81c99363f1c6aadb3f34b)
+++ src/cvec.c	(revision 1239d230255db345d182047be6736c0c884343b8)
@@ -140,2 +140,9 @@
   cvec_phas_zeros(s);
 }
+
+void cvec_logmag(cvec_t *s, smpl_t lambda) {
+  uint_t j;
+  for (j=0; j< s->length; j++) {
+    s->norm[j] = LOG(lambda * s->norm[j] + 1);
+  }
+}
Index: src/cvec.h
===================================================================
--- src/cvec.h	(revision a24a84ef787217ef02c81c99363f1c6aadb3f34b)
+++ src/cvec.h	(revision 1239d230255db345d182047be6736c0c884343b8)
@@ -231,4 +231,12 @@
 void cvec_zeros(cvec_t *s);
 
+/** take logarithmic magnitude
+
+  \param s input cvec to compress
+  \param lambda value to use for normalisation
+
+*/
+void cvec_logmag(cvec_t *s, smpl_t lambda);
+
 #ifdef __cplusplus
 }
Index: src/mathutils.c
===================================================================
--- src/mathutils.c	(revision a24a84ef787217ef02c81c99363f1c6aadb3f34b)
+++ src/mathutils.c	(revision 1239d230255db345d182047be6736c0c884343b8)
@@ -290,4 +290,23 @@
 }
 
+void fvec_push(fvec_t *in, smpl_t new_elem) {
+  uint_t i;
+  for (i = 0; i < in->length - 1; i++) {
+    in->data[i] = in->data[i + 1];
+  }
+  in->data[in->length - 1] = new_elem;
+}
+
+void fvec_clamp(fvec_t *in, smpl_t absmax) {
+  uint_t i;
+  for (i = 0; i < in->length; i++) {
+    if (in->data[i] > 0 && in->data[i] > ABS(absmax)) {
+      in->data[i] = absmax;
+    } else if (in->data[i] < 0 && in->data[i] < -ABS(absmax)) {
+      in->data[i] = -absmax;
+    }
+  }
+}
+
 smpl_t
 aubio_level_lin (const fvec_t * f)
Index: src/mathutils.h
===================================================================
--- src/mathutils.h	(revision a24a84ef787217ef02c81c99363f1c6aadb3f34b)
+++ src/mathutils.h	(revision 1239d230255db345d182047be6736c0c884343b8)
@@ -117,4 +117,15 @@
 */
 void fvec_ishift (fvec_t * v);
+
+/** push a new element to the end of a vector, erasing the first element and
+ * sliding all others
+
+  \param in vector to push to
+  \param new_elem new_element to add at the end of the vector
+
+  In numpy words, this is equivalent to: in = np.concatenate([in, [new_elem]])[1:]
+
+*/
+void fvec_push(fvec_t *in, smpl_t new_elem);
 
 /** compute the sum of all elements of a vector
Index: src/musicutils.h
===================================================================
--- src/musicutils.h	(revision a24a84ef787217ef02c81c99363f1c6aadb3f34b)
+++ src/musicutils.h	(revision 1239d230255db345d182047be6736c0c884343b8)
@@ -157,4 +157,12 @@
 smpl_t aubio_level_detection (const fvec_t * v, smpl_t threshold);
 
+/** clamp the values of a vector within the range [-abs(max), abs(max)]
+
+  \param in vector to clamp
+  \param absmax maximum value over which input vector elements should be clamped
+
+*/
+void fvec_clamp(fvec_t *in, smpl_t absmax);
+
 #ifdef __cplusplus
 }
Index: src/onset/onset.c
===================================================================
--- src/onset/onset.c	(revision a24a84ef787217ef02c81c99363f1c6aadb3f34b)
+++ src/onset/onset.c	(revision 1239d230255db345d182047be6736c0c884343b8)
@@ -24,7 +24,10 @@
 #include "spectral/specdesc.h"
 #include "spectral/phasevoc.h"
+#include "spectral/awhitening.h"
 #include "onset/peakpicker.h"
 #include "mathutils.h"
 #include "onset/onset.h"
+
+void aubio_onset_default_parameters (aubio_onset_t *o, const char_t * method);
 
 /** structure to store object state */
@@ -43,4 +46,9 @@
   uint_t total_frames;          /**< total number of frames processed since the beginning */
   uint_t last_onset;            /**< last detected onset location, in frames */
+
+  uint_t apply_compression;
+  smpl_t lambda_compression;
+  uint_t apply_adaptive_whitening;
+  aubio_spectral_whitening_t *spectral_whitening;
 };
 
@@ -50,4 +58,14 @@
   smpl_t isonset = 0;
   aubio_pvoc_do (o->pv,input, o->fftgrain);
+  /*
+  if (apply_filtering) {
+  }
+  */
+  if (o->apply_adaptive_whitening) {
+    aubio_spectral_whitening_do(o->spectral_whitening, o->fftgrain);
+  }
+  if (o->apply_compression) {
+    cvec_logmag(o->fftgrain, o->apply_compression);
+  }
   aubio_specdesc_do (o->od, o->fftgrain, o->desc);
   aubio_peakpicker_do(o->pp, o->desc, onset);
@@ -100,4 +118,15 @@
 }
 
+uint_t aubio_onset_set_adaptive_whitening (aubio_onset_t *o, uint_t apply_adaptive_whitening)
+{
+  o->apply_adaptive_whitening = apply_adaptive_whitening;
+  return AUBIO_OK;
+}
+
+uint_t aubio_onset_get_adaptive_whitening (aubio_onset_t *o)
+{
+  return o->apply_adaptive_whitening;
+}
+
 uint_t aubio_onset_set_silence(aubio_onset_t * o, smpl_t silence) {
   o->silence = silence;
@@ -210,9 +239,7 @@
   o->desc = new_fvec(1);
 
-  /* set some default parameter */
-  aubio_onset_set_threshold (o, 0.3);
-  aubio_onset_set_delay(o, 4.3 * hop_size);
-  aubio_onset_set_minioi_ms(o, 20.);
-  aubio_onset_set_silence(o, -70.);
+  o->spectral_whitening = new_aubio_spectral_whitening(buf_size, hop_size, samplerate);
+
+  aubio_onset_default_parameters (o, onset_mode);
 
   /* initialize internal variables */
@@ -229,6 +256,48 @@
 }
 
+void aubio_onset_default_parameters (aubio_onset_t * o, const char_t * onset_mode)
+{
+  /* set some default parameter */
+  aubio_onset_set_threshold (o, 0.3);
+  aubio_onset_set_delay (o, 4.3 * o->hop_size);
+  aubio_onset_set_minioi_ms (o, 50.);
+  aubio_onset_set_silence (o, -70.);
+  aubio_onset_set_adaptive_whitening (o, 0);
+
+  o->apply_compression = 0;
+  o->lambda_compression = 1.;
+
+  /* method specific optimisations */
+  if (strcmp (onset_mode, "energy") == 0) {
+  } else if (strcmp (onset_mode, "hfc") == 0 || strcmp (onset_mode, "default") == 0) {
+    aubio_onset_set_threshold (o, 0.058);
+    o->apply_compression = 1;
+    o->lambda_compression = 1.;
+    aubio_onset_set_adaptive_whitening (o, 0);
+  } else if (strcmp (onset_mode, "complexdomain") == 0
+             || strcmp (onset_mode, "complex") == 0) {
+    aubio_onset_set_delay (o, 4.6 * o->hop_size);
+    aubio_onset_set_threshold (o, 0.15);
+    o->apply_compression = 1;
+    o->lambda_compression = 1.;
+  } else if (strcmp (onset_mode, "phase") == 0) {
+    o->apply_compression = 0;
+    aubio_onset_set_adaptive_whitening (o, 0);
+  } else if (strcmp (onset_mode, "mkl") == 0) {
+    aubio_onset_set_threshold (o, 0.05);
+  } else if (strcmp (onset_mode, "kl") == 0) {
+    aubio_onset_set_threshold (o, 0.35);
+  } else if (strcmp (onset_mode, "specflux") == 0) {
+    aubio_onset_set_threshold (o, 0.4);
+  } else if (strcmp (onset_mode, "specdiff") == 0) {
+  } else {
+    AUBIO_WRN("onset: unknown spectral descriptor type %s, "
+               "using default parameters.\n", onset_mode);
+  }
+}
+
 void del_aubio_onset (aubio_onset_t *o)
 {
+  del_aubio_spectral_whitening(o->spectral_whitening);
   del_aubio_specdesc(o->od);
   del_aubio_peakpicker(o->pp);
Index: src/onset/onset.h
===================================================================
--- src/onset/onset.h	(revision a24a84ef787217ef02c81c99363f1c6aadb3f34b)
+++ src/onset/onset.h	(revision 1239d230255db345d182047be6736c0c884343b8)
@@ -118,4 +118,21 @@
 smpl_t aubio_onset_get_last_ms (const aubio_onset_t *o);
 
+/** set onset detection adaptive whitening
+
+  \param o onset detection object as returned by new_aubio_onset()
+  \param apply_adaptive_whitening 1 to enable, 0 to disable
+
+*/
+uint_t aubio_onset_set_adaptive_whitening(aubio_onset_t * o, uint_t apply_adaptive_whitening);
+
+/** get onset detection silence threshold
+
+  \param o onset detection object as returned by new_aubio_onset()
+
+  \return adaptive whitening mode, 1 if enabled, 0 otherwise
+
+*/
+uint_t aubio_onset_get_adaptive_whitening(aubio_onset_t * o);
+
 /** set onset detection silence threshold
 
Index: src/onset/peakpicker.c
===================================================================
--- src/onset/peakpicker.c	(revision a24a84ef787217ef02c81c99363f1c6aadb3f34b)
+++ src/onset/peakpicker.c	(revision 1239d230255db345d182047be6736c0c884343b8)
@@ -93,25 +93,19 @@
   fvec_t *scratch = p->scratch;
   smpl_t mean = 0., median = 0.;
-  uint_t length = p->win_post + p->win_pre + 1;
   uint_t j = 0;
 
-  /* store onset in onset_keep */
-  /* shift all elements but last, then write last */
-  for (j = 0; j < length - 1; j++) {
-    onset_keep->data[j] = onset_keep->data[j + 1];
-    onset_proc->data[j] = onset_keep->data[j];
-  }
-  onset_keep->data[length - 1] = onset->data[0];
-  onset_proc->data[length - 1] = onset->data[0];
+  /* push new novelty to the end */
+  fvec_push(onset_keep, onset->data[0]);
+  /* store a copy */
+  fvec_copy(onset_keep, onset_proc);
 
-  /* filter onset_proc */
-  /** \bug filtfilt calculated post+pre times, should be only once !? */
+  /* filter this copy */
   aubio_filter_do_filtfilt (p->biquad, onset_proc, scratch);
 
   /* calculate mean and median for onset_proc */
   mean = fvec_mean (onset_proc);
-  /* copy to scratch */
-  for (j = 0; j < length; j++)
-    scratch->data[j] = onset_proc->data[j];
+
+  /* copy to scratch and compute its median */
+  fvec_copy(onset_proc, scratch);
   median = p->thresholdfn (scratch);
 
Index: src/spectral/awhitening.c
===================================================================
--- src/spectral/awhitening.c	(revision 1239d230255db345d182047be6736c0c884343b8)
+++ src/spectral/awhitening.c	(revision 1239d230255db345d182047be6736c0c884343b8)
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2003-2015 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/>.
+ *
+ */
+
+#include "aubio_priv.h"
+#include "fvec.h"
+#include "cvec.h"
+#include "mathutils.h"
+#include "spectral/awhitening.h"
+
+#define aubio_spectral_whitening_default_relax_time   250   // in seconds, between 22 and 446
+#define aubio_spectral_whitening_default_decay        0.001 // -60dB attenuation
+#define aubio_spectral_whitening_default_floor        1.e-4 // from 1.e-6 to .2
+
+/** structure to store object state */
+struct _aubio_spectral_whitening_t {
+  uint_t buf_size;
+  uint_t hop_size;
+  uint_t samplerate;
+  smpl_t relax_time;
+  smpl_t r_decay;
+  smpl_t floor;
+  fvec_t *peak_values;
+};
+
+void
+aubio_spectral_whitening_do (aubio_spectral_whitening_t * o, cvec_t * fftgrain)
+{
+  uint_t i = 0;
+  for (i = 0; i < o->peak_values->length; i++) {
+    smpl_t tmp = MAX(o->r_decay * o->peak_values->data[i], o->floor);
+    o->peak_values->data[i] = MAX(fftgrain->norm[i], tmp);
+    fftgrain->norm[i] /= o->peak_values->data[i];
+  }
+}
+
+aubio_spectral_whitening_t *
+new_aubio_spectral_whitening (uint_t buf_size, uint_t hop_size, uint_t samplerate)
+{
+  aubio_spectral_whitening_t *o = AUBIO_NEW (aubio_spectral_whitening_t);
+  if ((sint_t)buf_size < 1) {
+    AUBIO_ERR("spectral_whitening: got buffer_size %d, but can not be < 1\n", buf_size);
+    goto beach;
+  } else if ((sint_t)hop_size < 1) {
+    AUBIO_ERR("spectral_whitening: got hop_size %d, but can not be < 1\n", hop_size);
+    goto beach;
+  } else if ((sint_t)samplerate < 1) {
+    AUBIO_ERR("spectral_whitening: got samplerate %d, but can not be < 1\n", samplerate);
+    goto beach;
+  }
+  o->peak_values = new_fvec (buf_size / 2 + 1);
+  o->buf_size = buf_size;
+  o->hop_size = hop_size;
+  o->samplerate = samplerate;
+  o->floor = aubio_spectral_whitening_default_floor;
+  aubio_spectral_whitening_set_relax_time (o, aubio_spectral_whitening_default_relax_time);
+  aubio_spectral_whitening_reset (o);
+  return o;
+
+beach:
+  AUBIO_FREE(o);
+  return NULL;
+}
+
+uint_t
+aubio_spectral_whitening_set_relax_time (aubio_spectral_whitening_t * o, smpl_t relax_time)
+{
+  o->relax_time = relax_time;
+  o->r_decay = POW (aubio_spectral_whitening_default_decay,
+      (o->hop_size / (float) o->samplerate) / o->relax_time);
+  return AUBIO_OK;
+}
+
+smpl_t
+aubio_spectral_whitening_get_relax_time (aubio_spectral_whitening_t * o)
+{
+  return o->relax_time;
+}
+
+void
+aubio_spectral_whitening_reset (aubio_spectral_whitening_t * o)
+{
+  /* cover the case n == 0. */
+  fvec_set_all (o->peak_values, o->floor);
+}
+
+void
+del_aubio_spectral_whitening (aubio_spectral_whitening_t * o)
+{
+  del_fvec (o->peak_values);
+  AUBIO_FREE (o);
+}
Index: src/spectral/awhitening.h
===================================================================
--- src/spectral/awhitening.h	(revision 1239d230255db345d182047be6736c0c884343b8)
+++ src/spectral/awhitening.h	(revision 1239d230255db345d182047be6736c0c884343b8)
@@ -0,0 +1,108 @@
+/*
+  Copyright (C) 2003-2015 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/>.
+
+*/
+
+/** \file
+
+  Spectral adaptive whitening
+
+  References:
+
+  D. Stowell and M. D. Plumbley. Adaptive whitening for improved real-time
+  audio onset detection. In Proceedings of the International Computer Music
+  Conference (ICMC), 2007, Copenhagen, Denmark.
+
+  http://www.eecs.qmul.ac.uk/~markp/2007/StowellPlumbley07-icmc.pdf
+
+  S. Böck,, F. Krebs, and M. Schedl. Evaluating the Online Capabilities of
+  Onset Detection Methods. In Proceedings of the 13th International Society for
+  Music Information Retrieval Conference (ISMIR), 2012, Porto, Portugal.
+
+  http://ismir2012.ismir.net/event/papers/049_ISMIR_2012.pdf
+  http://www.cp.jku.at/research/papers/Boeck_etal_ISMIR_2012.pdf
+
+*/
+
+
+#ifndef _AUBIO_SPECTRAL_WHITENING_H
+#define _AUBIO_SPECTRAL_WHITENING_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** spectral whitening structure */
+typedef struct _aubio_spectral_whitening_t aubio_spectral_whitening_t;
+
+/** execute spectral adaptive whitening, in-place
+
+  \param o spectral whitening object as returned by new_aubio_spectral_whitening()
+  \param fftgrain input signal spectrum as computed by aubio_pvoc_do() or aubio_fft_do()
+
+*/
+void aubio_spectral_whitening_do (aubio_spectral_whitening_t * o,
+                                  cvec_t * fftgrain);
+
+/** creation of a spectral whitening object
+
+  \param buf_size window size of input grains
+  \param hop_size number of samples between two consecutive input grains
+  \param samplerate sampling rate of the input signal
+
+*/
+aubio_spectral_whitening_t *new_aubio_spectral_whitening (uint_t buf_size,
+                                                          uint_t hop_size,
+                                                          uint_t samplerate);
+
+/** reset spectral whitening object
+
+  \param o spectral whitening object as returned by new_aubio_spectral_whitening()
+
+ */
+void aubio_spectral_whitening_reset (aubio_spectral_whitening_t * o);
+
+/** set relaxation time for spectral whitening
+
+  \param o spectral whitening object as returned by new_aubio_spectral_whitening()
+  \param relax_time relaxation time in seconds
+
+  */
+uint_t aubio_spectral_whitening_set_relax_time (aubio_spectral_whitening_t * o,
+    smpl_t relax_time);
+
+/** get relaxation time of spectral whitening
+
+  \param o spectral whitening object as returned by new_aubio_spectral_whitening()
+  \return relaxation time in seconds
+
+*/
+smpl_t aubio_spectral_whitening_get_relax_time (aubio_spectral_whitening_t * o);
+
+/** deletion of a spectral whitening
+
+  \param o spectral whitening object as returned by new_aubio_spectral_whitening()
+
+*/
+void del_aubio_spectral_whitening (aubio_spectral_whitening_t * o);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _AUBIO_SPECTRAL_WHITENING_H */
Index: src/spectral/specdesc.c
===================================================================
--- src/spectral/specdesc.c	(revision a24a84ef787217ef02c81c99363f1c6aadb3f34b)
+++ src/spectral/specdesc.c	(revision 1239d230255db345d182047be6736c0c884343b8)
@@ -31,4 +31,5 @@
 void aubio_specdesc_complex(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
 void aubio_specdesc_phase(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
+void aubio_specdesc_wphase(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
 void aubio_specdesc_specdiff(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
 void aubio_specdesc_kl(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
@@ -58,4 +59,5 @@
         aubio_onset_complex,        /**< complex domain */        
         aubio_onset_phase,          /**< phase fast */            
+        aubio_onset_wphase,         /**< weighted phase */
         aubio_onset_kl,             /**< Kullback Liebler */
         aubio_onset_mkl,            /**< modified Kullback Liebler */
@@ -158,4 +160,21 @@
   onset->data[0] = aubio_hist_mean(o->histog);  
   //onset->data[0] = fvec_mean(o->dev1);
+}
+
+/* weighted phase */
+void
+aubio_specdesc_wphase(aubio_specdesc_t *o,
+    const cvec_t *fftgrain, fvec_t *onset) {
+  uint_t i;
+  aubio_specdesc_phase(o, fftgrain, onset);
+  for (i = 0; i < fftgrain->length; i++) {
+    o->dev1->data[i] *= fftgrain->norm[i];
+  }
+  /* apply o->histogram */
+  aubio_hist_dyn_notnull(o->histog,o->dev1);
+  /* weight it */
+  aubio_hist_weight(o->histog);
+  /* its mean is the result */
+  onset->data[0] = aubio_hist_mean(o->histog);
 }
 
@@ -251,4 +270,6 @@
   else if (strcmp (onset_mode, "phase") == 0)
       onset_type = aubio_onset_phase;
+  else if (strcmp (onset_mode, "wphase") == 0)
+      onset_type = aubio_onset_wphase;
   else if (strcmp (onset_mode, "mkl") == 0)
       onset_type = aubio_onset_mkl;
@@ -292,4 +313,5 @@
       break;
     case aubio_onset_phase:
+    case aubio_onset_wphase:
       o->dev1   = new_fvec(rsize);
       o->theta1 = new_fvec(rsize);
@@ -326,4 +348,7 @@
       o->funcpointer = aubio_specdesc_phase;
       break;
+    case aubio_onset_wphase:
+      o->funcpointer = aubio_specdesc_wphase;
+      break;
     case aubio_onset_specdiff:
       o->funcpointer = aubio_specdesc_specdiff;
@@ -379,4 +404,5 @@
       break;
     case aubio_onset_phase:
+    case aubio_onset_wphase:
       del_fvec(o->dev1);
       del_fvec(o->theta1);
Index: src/spectral/specdesc.h
===================================================================
--- src/spectral/specdesc.h	(revision a24a84ef787217ef02c81c99363f1c6aadb3f34b)
+++ src/spectral/specdesc.h	(revision 1239d230255db345d182047be6736c0c884343b8)
@@ -60,4 +60,11 @@
   Hong-Kong, 2003.
 
+  \b \p wphase : Weighted Phase Deviation onset detection function
+
+  S. Dixon. Onset detection revisited. In Proceedings of the 9th International
+  Conference on Digital Audio Ef- fects (DAFx) , pages 133–137, 2006.
+
+  http://www.eecs.qmul.ac.uk/~simond/pub/2006/dafx.pdf
+
   \b \p specdiff : Spectral difference method onset detection function
 
@@ -175,6 +182,9 @@
   The parameter \p method is a string that can be any of:
 
-    - `energy`, `hfc`, `complex`, `phase`, `specdiff`, `kl`, `mkl`, `specflux`
-    - `centroid`, `spread`, `skewness`, `kurtosis`, `slope`, `decrease`, `rolloff`
+    - onset novelty functions: `complex`, `energy`, `hfc`, `kl`, `mkl`,
+    `phase`, `specdiff`, `specflux`, `wphase`,
+
+    - spectral descriptors: `centroid`, `decrease`, `kurtosis`, `rolloff`,
+    `skewness`, `slope`, `spread`.
 
 */
Index: tests/src/spectral/test-awhitening.c
===================================================================
--- tests/src/spectral/test-awhitening.c	(revision 1239d230255db345d182047be6736c0c884343b8)
+++ tests/src/spectral/test-awhitening.c	(revision 1239d230255db345d182047be6736c0c884343b8)
@@ -0,0 +1,84 @@
+#include <aubio.h>
+#include "utils_tests.h"
+
+int main (int argc, char **argv)
+{
+  sint_t err = 0;
+
+  if (argc < 3) {
+    err = 2;
+    PRINT_ERR("not enough arguments\n");
+    PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
+    return err;
+  }
+
+  uint_t samplerate = 0;
+  uint_t win_size = 1024;
+  uint_t hop_size = 512;
+  uint_t n_frames = 0, read = 0;
+
+  char_t *source_path = argv[1];
+  char_t *sink_path = argv[2];
+
+  if ( argc >= 4 ) samplerate = atoi(argv[3]);
+  if ( argc >= 5 ) hop_size = atoi(argv[4]);
+  if ( argc >= 6 ) {
+    err = 2;
+    PRINT_ERR("too many arguments\n");
+    return err;
+  }
+
+  fvec_t *vec = new_fvec(hop_size);
+  fvec_t *out = new_fvec(hop_size); // output buffer
+  fvec_t *scale = new_fvec(hop_size);
+  cvec_t *fftgrain = new_cvec(win_size); // fft norm and phase
+  if (!vec) { err = 1; goto beach_fvec; }
+
+  aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
+  if (!i) { err = 1; goto beach_source; }
+
+  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
+
+  aubio_sink_t *o = new_aubio_sink(sink_path, samplerate);
+  if (!o) { err = 1; goto beach_sink; }
+
+  aubio_pvoc_t *pv = new_aubio_pvoc(win_size, hop_size);
+
+  aubio_spectral_whitening_t *awhitening =
+    new_aubio_spectral_whitening (win_size, hop_size, samplerate);
+
+  aubio_spectral_whitening_set_relax_time(awhitening, 20.);
+  fvec_set_all(scale, 3.);
+
+  PRINT_MSG("spectral whitening relaxation time is %f\n",
+      aubio_spectral_whitening_get_relax_time(awhitening));
+
+  do {
+    aubio_source_do(i, vec, &read);
+    aubio_pvoc_do(pv, vec, fftgrain);
+    // apply spectral whitening
+    aubio_spectral_whitening_do(awhitening, fftgrain);
+    // rebuild the signal
+    aubio_pvoc_rdo(pv, fftgrain, out);
+    // make louder
+    fvec_weight(out, scale);
+    // make sure we dont saturate
+    fvec_clamp(out, 1.);
+    // write output
+    aubio_sink_do(o, out, read);
+    n_frames += read;
+  } while ( read == hop_size );
+
+  PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
+      n_frames, samplerate, n_frames / hop_size,
+      source_path, sink_path);
+
+  del_aubio_sink(o);
+beach_sink:
+  del_aubio_source(i);
+beach_source:
+  del_fvec(vec);
+beach_fvec:
+  return err;
+}
+
