Index: src/onset/onset.c
===================================================================
--- src/onset/onset.c	(revision f5e0a54442912496c3796085820a74451ab89bf1)
+++ src/onset/onset.c	(revision adc47c9c432e386296db329dddd6a8701462ab9b)
@@ -39,5 +39,4 @@
   uint_t minioi;                /**< minimum inter onset interval */
   uint_t delay;                 /**< constant delay, in samples, removed from detected onset times */
-  fvec_t * wasonset;            /**< number of blocks since last onset */
   uint_t samplerate;            /**< sampling rate of the input signal */
   uint_t hop_size;              /**< number of samples between two runs */
@@ -51,37 +50,28 @@
 {
   smpl_t isonset = 0;
-  smpl_t wasonset = 0;
   aubio_pvoc_do (o->pv,input, o->fftgrain);
   aubio_specdesc_do (o->od,o->fftgrain, o->of);
   aubio_peakpicker_do(o->pp, o->of, onset);
   isonset = onset->data[0];
-  wasonset = o->wasonset->data[0];
   if (isonset > 0.) {
     if (aubio_silence_detection(input, o->silence)==1) {
       isonset  = 0;
-      wasonset++;
     } else {
-      if (wasonset > o->minioi) {
-        wasonset = 0;
-        o->last_onset = o->total_frames + isonset * o->hop_size;
+      uint_t new_onset = o->total_frames + isonset * o->hop_size;
+      if (o->last_onset + o->minioi < new_onset) {
+        o->last_onset = new_onset;
       } else {
         isonset  = 0;
-        wasonset++;
       }
     }
   } else {
-    if (wasonset == -1 && aubio_silence_detection(input, o->silence) == 0) {
-      //AUBIO_MSG("beginning of file is not silent, marking as onset\n",
-      //  wasonset, aubio_silence_detection(input, o->silence));
+    // we are at the beginning of the file, and we don't find silence
+    if (o->total_frames == 0 && aubio_silence_detection(input, o->silence) == 0) {
+      //AUBIO_DBG ("beginning of file is not silent, marking as onset\n");
       isonset = o->delay / o->hop_size;
       o->last_onset = o->delay;
-      wasonset = 0;
     }
-    wasonset++;
   }
-  o->wasonset->data[0] = wasonset;
-  //onset->data[0] = isonset * o->hop_size - o->delay;
   onset->data[0] = isonset;
-  // also keep a copy of the offset for use in get_last_onset
   o->total_frames += o->hop_size;
   return;
@@ -103,13 +93,4 @@
 }
 
-smpl_t aubio_onset_get_descriptor(aubio_onset_t * o) {
-  return o->of->data[0];
-}
-
-smpl_t aubio_onset_get_thresholded_descriptor(aubio_onset_t * o) {
-  fvec_t * thresholded = aubio_peakpicker_get_thresholded_input(o->pp);
-  return thresholded->data[0];
-}
-
 uint_t aubio_onset_set_silence(aubio_onset_t * o, smpl_t silence) {
   o->silence = silence;
@@ -124,5 +105,5 @@
 
 uint_t aubio_onset_set_minioi(aubio_onset_t * o, uint_t minioi) {
-  o->minioi = FLOOR(minioi / 1000. * o->samplerate / o->hop_size);
+  o->minioi = minioi;
   return AUBIO_OK;
 }
@@ -130,4 +111,20 @@
 uint_t aubio_onset_get_minioi(aubio_onset_t * o) {
   return o->minioi;
+}
+
+uint_t aubio_onset_set_minioi_s(aubio_onset_t * o, smpl_t minioi) {
+  return aubio_onset_set_minioi (o, minioi * o->samplerate);
+}
+
+smpl_t aubio_onset_get_minioi_s(aubio_onset_t * o) {
+  return aubio_onset_get_minioi (o) / (smpl_t) o->samplerate;
+}
+
+uint_t aubio_onset_set_minioi_ms(aubio_onset_t * o, smpl_t minioi) {
+  return aubio_onset_set_minioi_s (o, minioi / 1000.);
+}
+
+smpl_t aubio_onset_get_minioi_ms(aubio_onset_t * o) {
+  return aubio_onset_get_minioi_s (o) * 1000.;
 }
 
@@ -157,4 +154,13 @@
 }
 
+smpl_t aubio_onset_get_descriptor(aubio_onset_t * o) {
+  return o->of->data[0];
+}
+
+smpl_t aubio_onset_get_thresholded_descriptor(aubio_onset_t * o) {
+  fvec_t * thresholded = aubio_peakpicker_get_thresholded_input(o->pp);
+  return thresholded->data[0];
+}
+
 /* Allocate memory for an onset detection */
 aubio_onset_t * new_aubio_onset (char_t * onset_mode, 
@@ -163,15 +169,13 @@
   aubio_onset_t * o = AUBIO_NEW(aubio_onset_t);
   /** set some default parameter */
+  o->samplerate = samplerate;
+  o->hop_size = hop_size;
   o->last_onset = 0;
   o->threshold = 0.3;
   o->delay     = 4.3 * hop_size;
-  o->minioi    = 5;
+  o->minioi    = 5 * hop_size;
   o->silence   = -70;
-  o->wasonset  = new_fvec(1);
-  o->wasonset->data[0] = -1.;
   o->total_frames = 0;
-  o->samplerate = samplerate;
-  o->hop_size = hop_size;
-  o->pv = new_aubio_pvoc(buf_size, hop_size);
+  o->pv = new_aubio_pvoc(buf_size, o->hop_size);
   o->pp = new_aubio_peakpicker();
   aubio_peakpicker_set_threshold (o->pp, o->threshold);
@@ -179,8 +183,4 @@
   o->fftgrain = new_cvec(buf_size);
   o->of = new_fvec(1);
-  /*if (usedoubled)    {
-    o2 = new_aubio_specdesc(onset_type2,buffer_size);
-    onset2 = new_fvec(1);
-  }*/
   return o;
 }
@@ -192,5 +192,4 @@
   del_aubio_pvoc(o->pv);
   del_fvec(o->of);
-  del_fvec(o->wasonset);
   del_cvec(o->fftgrain);
   AUBIO_FREE(o);
Index: src/onset/onset.h
===================================================================
--- src/onset/onset.h	(revision f5e0a54442912496c3796085820a74451ab89bf1)
+++ src/onset/onset.h	(revision adc47c9c432e386296db329dddd6a8701462ab9b)
@@ -20,5 +20,5 @@
 
 /** \file
- 
+
   Onset detection object
 
@@ -49,19 +49,38 @@
 
 /** create onset detection object
-  
+
   \param method onset detection type as specified in specdesc.h
   \param buf_size buffer size for phase vocoder
   \param hop_size hop size for phase vocoder
-  \param samplerate sampling rate of the input signal 
-
-*/
-aubio_onset_t * new_aubio_onset (char_t * method, 
+  \param samplerate sampling rate of the input signal
+
+*/
+aubio_onset_t * new_aubio_onset (char_t * method,
     uint_t buf_size, uint_t hop_size, uint_t samplerate);
 
 /** execute onset detection
 
-  \param o onset detection object as returned by new_aubio_onset
+  \param o onset detection object as returned by ::new_aubio_onset
   \param input new audio vector of length hop_size
-  \param onset output vector, 1 if onset is found, 0 otherwise
+  \param onset output vector of length 1, containing 0 if no onset was found,
+  and a value equal or greater than 1 otherwise
+
+  When no onset was detected, the first element of the output vector `onset`
+  is set to 0.
+
+  When an onset is found, the first element of the output vector `onset` is set
+  to `offset = 1 + a` where `a` is a number in the range`[0, 1]`.
+
+  The final onset detection time, in samples, can be obtained with
+  ::aubio_onset_get_last_onset. It can also be derived from `offset` as
+  follows:
+
+  \code
+    t = total_frames + offset * hop_size - delay
+  \endcode
+
+  where `total_frames` is the total number of frames processed so far, and
+  `delay` is the current delay of the onset object, as returned by
+  ::aubio_onset_get_delay.
 
 */
@@ -70,5 +89,5 @@
 /** get the time of the latest onset detected, in samples
 
-  \param o onset detection object as returned by new_aubio_onset
+  \param o onset detection object as returned by ::new_aubio_onset
 
 */
@@ -77,5 +96,5 @@
 /** get the time of the latest onset detected, in seconds
 
-  \param o onset detection object as returned by new_aubio_onset
+  \param o onset detection object as returned by ::new_aubio_onset
 
 */
@@ -84,5 +103,5 @@
 /** get the time of the latest onset detected, in milliseconds
 
-  \param o onset detection object as returned by new_aubio_onset
+  \param o onset detection object as returned by ::new_aubio_onset
 
 */
@@ -91,5 +110,5 @@
 /** set onset detection silence threshold
 
-  \param o onset detection object as returned by new_aubio_onset
+  \param o onset detection object as returned by ::new_aubio_onset
   \param silence new silence detection threshold
 
@@ -99,5 +118,5 @@
 /** get onset detection function
 
-  \param o onset detection object as returned by new_aubio_onset
+  \param o onset detection object as returned by ::new_aubio_onset
   \return the current value of the descriptor
 
@@ -107,5 +126,5 @@
 /** get thresholded onset detection function
 
-  \param o onset detection object as returned by new_aubio_onset
+  \param o onset detection object as returned by ::new_aubio_onset
   \return the value of the thresholded descriptor
 
@@ -113,7 +132,7 @@
 smpl_t aubio_onset_get_thresholded_descriptor ( aubio_onset_t *o);
 
-/** set onset detection peak picking threshold 
-
-  \param o onset detection object as returned by new_aubio_onset
+/** set onset detection peak picking threshold
+
+  \param o onset detection object as returned by ::new_aubio_onset
   \param threshold new peak-picking threshold
 
@@ -121,16 +140,115 @@
 uint_t aubio_onset_set_threshold(aubio_onset_t * o, smpl_t threshold);
 
-/** set minimum inter onset interval
-
-  \param o onset detection object as returned by new_aubio_onset
+/** set minimum inter onset interval in samples
+
+  \param o onset detection object as returned by ::new_aubio_onset
+  \param minioi minimum interval between two consecutive onsets (in
+  samples)
+
+*/
+uint_t aubio_onset_set_minioi(aubio_onset_t * o, uint_t minioi);
+
+/** set minimum inter onset interval in seconds
+
+  \param o onset detection object as returned by ::new_aubio_onset
+  \param minioi minimum interval between two consecutive onsets (in
+  seconds)
+
+*/
+uint_t aubio_onset_set_minioi_s(aubio_onset_t * o, smpl_t minioi);
+
+/** set minimum inter onset interval in milliseconds
+
+  \param o onset detection object as returned by ::new_aubio_onset
   \param minioi minimum interval between two consecutive onsets (in
   milliseconds)
 
 */
-uint_t aubio_onset_set_minioi(aubio_onset_t * o, uint_t minioi);
+uint_t aubio_onset_set_minioi_ms(aubio_onset_t * o, smpl_t minioi);
+
+/** set minimum inter onset interval in samples
+
+  \param o onset detection object as returned by ::new_aubio_onset
+  \param delay constant system delay to take back from detection time
+  (in samples)
+
+*/
+uint_t aubio_onset_set_delay(aubio_onset_t * o, uint_t delay);
+
+/** set minimum inter onset interval in seconds
+
+  \param o onset detection object as returned by ::new_aubio_onset
+  \param delay constant system delay to take back from detection time
+  (in seconds)
+
+*/
+uint_t aubio_onset_set_delay_s(aubio_onset_t * o, smpl_t delay);
+
+/** set minimum inter onset interval in milliseconds
+
+  \param o onset detection object as returned by ::new_aubio_onset
+  \param delay constant system delay to take back from detection time
+  (in milliseconds)
+
+*/
+uint_t aubio_onset_set_delay_ms(aubio_onset_t * o, smpl_t delay);
+
+/** get minimum inter onset interval in samples
+
+  \param o onset detection object as returned by ::new_aubio_onset
+  \return minimum interval between two consecutive onsets (in
+  samples)
+
+*/
+uint_t aubio_onset_get_minioi(aubio_onset_t * o);
+
+/** get minimum inter onset interval in seconds
+
+  \param o onset detection object as returned by ::new_aubio_onset
+  \return minimum interval between two consecutive onsets (in
+  seconds)
+
+*/
+smpl_t aubio_onset_get_minioi_s(aubio_onset_t * o);
+
+/** get minimum inter onset interval in milliseconds
+
+  \param o onset detection object as returned by ::new_aubio_onset
+  \return minimum interval between two consecutive onsets (in
+  milliseconds)
+
+*/
+smpl_t aubio_onset_get_minioi_ms(aubio_onset_t * o);
+
+/** get minimum inter onset interval in samples
+
+  \param o onset detection object as returned by ::new_aubio_onset
+  \return constant system delay to take back from detection time
+  (in samples)
+
+*/
+uint_t aubio_onset_get_delay(aubio_onset_t * o);
+
+/** get minimum inter onset interval in seconds
+
+  \param o onset detection object as returned by ::new_aubio_onset
+  \return constant system delay to take back from detection time
+  (in seconds)
+
+*/
+smpl_t aubio_onset_get_delay_s(aubio_onset_t * o);
+
+/** get minimum inter onset interval in milliseconds
+
+  \param o onset detection object as returned by ::new_aubio_onset
+  \return constant system delay to take back from detection time
+  (in milliseconds)
+
+*/
+smpl_t aubio_onset_get_delay_ms(aubio_onset_t * o);
 
 /** delete onset detection object
 
-  \param o onset detection object to delete 
+  \param o onset detection object to delete
 
 */
