src/onset: mono
authorPaul Brossier <piem@piem.org>
Fri, 4 Dec 2009 00:34:44 +0000 (01:34 +0100)
committerPaul Brossier <piem@piem.org>
Fri, 4 Dec 2009 00:34:44 +0000 (01:34 +0100)
src/onset/onset.c
src/onset/onset.h
src/onset/peakpicker.c
src/onset/peakpicker.h

index fee3374..b556345 100644 (file)
@@ -47,17 +47,11 @@ void aubio_onset_do (aubio_onset_t *o, fvec_t * input, fvec_t * onset)
 {
   smpl_t isonset = 0;
   smpl_t wasonset = 0;
-  uint_t i;
   aubio_pvoc_do (o->pv,input, o->fftgrain);
   aubio_specdesc_do (o->od,o->fftgrain, o->of);
-  /*if (usedoubled) {
-    aubio_specdesc_do (o2,fftgrain, onset2);
-    onset->data[0][0] *= onset2->data[0][0];
-  }*/
   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];
+  isonset = onset->data[0];
+  wasonset = o->wasonset->data[0];
   if (isonset > 0.) {
     if (aubio_silence_detection(input, o->silence)==1) {
       isonset  = 0;
@@ -73,9 +67,8 @@ void aubio_onset_do (aubio_onset_t *o, fvec_t * input, fvec_t * onset)
   } else {
     wasonset++;
   }
-  o->wasonset->data[i][0] = wasonset;
-  onset->data[i][0] = isonset;
-  }
+  o->wasonset->data[0] = wasonset;
+  onset->data[0] = isonset;
   return;
 }
 
@@ -97,25 +90,25 @@ uint_t aubio_onset_set_minioi(aubio_onset_t * o, uint_t minioi) {
 
 /* Allocate memory for an onset detection */
 aubio_onset_t * new_aubio_onset (char_t * onset_mode, 
-    uint_t buf_size, uint_t hop_size, uint_t channels, uint_t samplerate)
+    uint_t buf_size, uint_t hop_size, uint_t samplerate)
 {
   aubio_onset_t * o = AUBIO_NEW(aubio_onset_t);
   /** set some default parameter */
   o->threshold = 0.3;
   o->minioi    = 4;
   o->silence   = -70;
-  o->wasonset  = new_fvec(1, channels);
+  o->wasonset  = new_fvec(1);
   o->samplerate = samplerate;
   o->hop_size = hop_size;
-  o->pv = new_aubio_pvoc(buf_size, hop_size, channels);
-  o->pp = new_aubio_peakpicker(channels);
+  o->pv = new_aubio_pvoc(buf_size, hop_size);
+  o->pp = new_aubio_peakpicker();
   aubio_peakpicker_set_threshold (o->pp, o->threshold);
-  o->od = new_aubio_specdesc(onset_mode,buf_size,channels);
-  o->fftgrain = new_cvec(buf_size,channels);
-  o->of = new_fvec(1, channels);
+  o->od = new_aubio_specdesc(onset_mode,buf_size);
+  o->fftgrain = new_cvec(buf_size);
+  o->of = new_fvec(1);
   /*if (usedoubled)    {
-    o2 = new_aubio_specdesc(onset_type2,buffer_size,channels);
-    onset2 = new_fvec(1 , channels);
+    o2 = new_aubio_specdesc(onset_type2,buffer_size);
+    onset2 = new_fvec(1);
   }*/
   return o;
 }
index 8c1d7f9..ffae869 100644 (file)
@@ -49,12 +49,11 @@ typedef struct _aubio_onset_t aubio_onset_t;
   \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 channels number of channels 
   \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 channels, uint_t samplerate);
+    uint_t buf_size, uint_t hop_size, uint_t samplerate);
 
 /** execute onset detection
 
index 71985de..010c9a6 100644 (file)
@@ -27,7 +27,7 @@
 #include "onset/peakpicker.h"
 
 /** function pointer to thresholding function */
-typedef smpl_t (*aubio_thresholdfn_t)(fvec_t *input, uint_t channel);
+typedef smpl_t (*aubio_thresholdfn_t)(fvec_t *input);
 /** function pointer to peak-picking function */
 typedef uint_t (*aubio_pickerfn_t)(fvec_t *input, uint_t pos);
 
@@ -68,9 +68,6 @@ struct _aubio_peakpicker_t
         /** scratch pad for biquad and median */
   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] */
   /* smpl_t cutoff; */
@@ -96,42 +93,38 @@ aubio_peakpicker_do (aubio_peakpicker_t * p, fvec_t * onset, fvec_t * out)
   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;
-
-  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];
+  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];
 
   /* filter onset_proc */
   /** \bug filtfilt calculated post+pre times, should be only once !? */
   aubio_filter_do_filtfilt (p->biquad, onset_proc, 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);
-
-    /* shift peek array */
-    for (j = 0; j < 3 - 1; j++)
-      onset_peek->data[i][j] = onset_peek->data[i][j + 1];
-    /* calculate new tresholded value */
-    thresholded->data[i][0] =
-        onset_proc->data[i][p->win_post] - median - mean * p->threshold;
-    onset_peek->data[i][2] = thresholded->data[i][0];
-    out->data[i][0] = (p->pickerfn) (onset_peek, 1);
-    if (out->data[i][0]) {
-      out->data[i][0] = fvec_quadint (onset_peek, 1, i);
-    }
+  /* 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];
+  median = p->thresholdfn (scratch);
+
+  /* shift peek array */
+  for (j = 0; j < 3 - 1; j++)
+    onset_peek->data[j] = onset_peek->data[j + 1];
+  /* calculate new tresholded value */
+  thresholded->data[0] =
+      onset_proc->data[p->win_post] - median - mean * p->threshold;
+  onset_peek->data[2] = thresholded->data[0];
+  out->data[0] = (p->pickerfn) (onset_peek, 1);
+  if (out->data[0]) {
+    out->data[0] = fvec_quadint (onset_peek, 1);
   }
 }
 
@@ -172,29 +165,27 @@ aubio_peakpicker_get_thresholdfn (aubio_peakpicker_t * p)
 }
 
 aubio_peakpicker_t *
-new_aubio_peakpicker (uint_t channels)
+new_aubio_peakpicker ()
 {
   aubio_peakpicker_t *t = AUBIO_NEW (aubio_peakpicker_t);
   t->threshold = 0.1;           /* 0.0668; 0.33; 0.082; 0.033; */
   t->win_post = 5;
   t->win_pre = 1;
-  //channels = 1;
-  t->channels = channels;
 
-  t->thresholdfn = (aubio_thresholdfn_t) (fvec_median_channel); /* (fvec_mean); */
+  t->thresholdfn = (aubio_thresholdfn_t) (fvec_median); /* (fvec_mean); */
   t->pickerfn = (aubio_pickerfn_t) (fvec_peakpick);
 
-  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);
-  t->thresholded = new_fvec (1, channels);
+  t->scratch = new_fvec (t->win_post + t->win_pre + 1);
+  t->onset_keep = new_fvec (t->win_post + t->win_pre + 1);
+  t->onset_proc = new_fvec (t->win_post + t->win_pre + 1);
+  t->onset_peek = new_fvec (3);
+  t->thresholded = new_fvec (1);
 
   /* cutoff: low-pass filter with cutoff reduced frequency at 0.34
      generated with octave butter function: [b,a] = butter(2, 0.34);
    */
   t->biquad = new_aubio_filter_biquad (0.15998789, 0.31997577, 0.15998789,
-      -0.59488894, 0.23484048, channels);
+      -0.59488894, 0.23484048);
 
   return t;
 }
index 3f46ce7..d0685cf 100644 (file)
@@ -35,7 +35,7 @@ extern "C" {
 typedef struct _aubio_peakpicker_t aubio_peakpicker_t;
 
 /** peak-picker creation function */
-aubio_peakpicker_t * new_aubio_peakpicker(uint_t channels);
+aubio_peakpicker_t * new_aubio_peakpicker();
 /** real time peak picking function */
 void aubio_peakpicker_do(aubio_peakpicker_t * p, fvec_t * in, fvec_t * out);
 /** destroy peak picker structure */