shithub: aubio

Download patch

ref: 0b9a02a653bc4e9d33b82eb5369ce6a94a637eed
parent: 66fb3eac1f2656782d007d587b28cb62e93566b5
author: Paul Brossier <piem@piem.org>
date: Thu Dec 3 20:34:44 EST 2009

src/onset: mono

--- a/src/onset/onset.c
+++ b/src/onset/onset.c
@@ -47,17 +47,11 @@
 {
   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 @@
   } else {
     wasonset++;
   }
-  o->wasonset->data[i][0] = wasonset;
-  onset->data[i][0] = isonset;
-  }
+  o->wasonset->data[0] = wasonset;
+  onset->data[0] = isonset;
   return;
 }
 
@@ -97,7 +90,7 @@
 
 /* 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 */
@@ -104,18 +97,18 @@
   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;
 }
--- a/src/onset/onset.h
+++ b/src/onset/onset.h
@@ -49,12 +49,11 @@
   \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
 
--- a/src/onset/peakpicker.c
+++ b/src/onset/peakpicker.c
@@ -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 @@
         /** 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 @@
   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;
+  uint_t 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];
+  /* 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);
+  /* 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[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);
-    }
+  /* 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_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;
 }
--- a/src/onset/peakpicker.h
+++ b/src/onset/peakpicker.h
@@ -35,7 +35,7 @@
 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 */