shithub: aubio

Download patch

ref: b4f5967809d2ebb0a69d303048017cfad34927ac
parent: 27fa522078b15ed1000feda7a97103cba8b48bbc
author: Paul Brossier <[email protected]>
date: Thu Oct 15 13:09:34 EDT 2009

src/onset: use a string to set onset mode, keeping onset types enum private, update everywhere onsets are used

--- a/examples/aubiotrack.c
+++ b/examples/aubiotrack.c
@@ -80,7 +80,7 @@
   examples_common_init(argc,argv);
 
   out = new_fvec(2,channels);
-  bt  = new_aubio_tempo(type_onset,buffer_size,overlap_size,channels);
+  bt  = new_aubio_tempo(onset_mode,buffer_size,overlap_size,channels);
 
   examples_common_process(aubio_process,process_print);
 
--- a/examples/utils.c
+++ b/examples/utils.c
@@ -45,8 +45,7 @@
 
 
 /* energy,specdiff,hfc,complexdomain,phase */
-aubio_onsetdetection_type type_onset = aubio_onset_kl;
-aubio_onsetdetection_type type_onset2 = aubio_onset_complex;
+char_t * onset_mode = "default";
 smpl_t threshold = 0.3;
 smpl_t silence = -90.;
 uint_t buffer_size = 512;       //1024;
@@ -91,7 +90,6 @@
 
 
 /* badly redeclare some things */
-aubio_onsetdetection_type type_onset;
 smpl_t threshold;
 smpl_t averaging;
 const char *prog_name;
@@ -163,29 +161,7 @@
         usejack = 1;
         break;
       case 'O':                /*onset type */
-        if (strcmp (optarg, "energy") == 0)
-          type_onset = aubio_onset_energy;
-        else if (strcmp (optarg, "specdiff") == 0)
-          type_onset = aubio_onset_specdiff;
-        else if (strcmp (optarg, "hfc") == 0)
-          type_onset = aubio_onset_hfc;
-        else if (strcmp (optarg, "complexdomain") == 0)
-          type_onset = aubio_onset_complex;
-        else if (strcmp (optarg, "complex") == 0)
-          type_onset = aubio_onset_complex;
-        else if (strcmp (optarg, "phase") == 0)
-          type_onset = aubio_onset_phase;
-        else if (strcmp (optarg, "mkl") == 0)
-          type_onset = aubio_onset_mkl;
-        else if (strcmp (optarg, "kl") == 0)
-          type_onset = aubio_onset_kl;
-        else if (strcmp (optarg, "specflux") == 0)
-          type_onset = aubio_onset_specflux;
-        else {
-          errmsg ("unknown onset type.\n");
-          abort ();
-        }
-        usedoubled = 0;
+        onset_mode = optarg;
         break;
       case 's':                /* threshold value for onset */
         silence = (smpl_t) atof (optarg);
@@ -331,12 +307,8 @@
   pv = new_aubio_pvoc (buffer_size, overlap_size, channels);
   /* onsets */
   parms = new_aubio_peakpicker (threshold);
-  o = new_aubio_onsetdetection (type_onset, buffer_size, channels);
+  o = new_aubio_onsetdetection (onset_mode, buffer_size, channels);
   onset = new_fvec (1, channels);
-  if (usedoubled) {
-    o2 = new_aubio_onsetdetection (type_onset2, buffer_size, channels);
-    onset2 = new_fvec (1, channels);
-  }
 
 }
 
--- a/examples/utils.h
+++ b/examples/utils.h
@@ -78,8 +78,7 @@
 
 
 /* energy,specdiff,hfc,complexdomain,phase */
-extern aubio_onsetdetection_type type_onset;
-extern aubio_onsetdetection_type type_onset2;
+extern char_t * onset_mode;
 extern smpl_t threshold;
 extern smpl_t silence;
 extern uint_t buffer_size;
--- a/plugins/puredata/aubioonset~.c
+++ b/plugins/puredata/aubioonset~.c
@@ -87,7 +87,7 @@
 	x->bufsize   = 1024;
 	x->hopsize   = x->bufsize / 2;
 
-	x->o = new_aubio_onsetdetection(aubio_onset_complex, x->bufsize, 1);
+	x->o = new_aubio_onsetdetection("complex", x->bufsize, 1);
 	x->vec = (fvec_t *)new_fvec(x->hopsize,1);
 	x->pv = (aubio_pvoc_t *)new_aubio_pvoc(x->bufsize, x->hopsize, 1);
 	x->fftgrain  = (cvec_t *)new_cvec(x->bufsize,1);
--- a/plugins/puredata/aubiotempo~.c
+++ b/plugins/puredata/aubiotempo~.c
@@ -82,7 +82,7 @@
   x->bufsize   = 1024;
   x->hopsize   = x->bufsize / 2;
 
-  x->t = new_aubio_tempo (aubio_onset_complex, x->bufsize, x->hopsize, 1);
+  x->t = new_aubio_tempo ("complex", x->bufsize, x->hopsize, 1);
   aubio_tempo_set_silence(x->t,x->silence);
   aubio_tempo_set_threshold(x->t,x->threshold);
   x->output = (fvec_t *)new_fvec(2,1);
--- a/python/aubio/aubioclass.py
+++ b/python/aubio/aubioclass.py
@@ -69,8 +69,8 @@
 
 class onsetdetection:
     """ class for aubio_onsetdetection """
-    def __init__(self,type,buf,chan):
-        self.od = new_aubio_onsetdetection(type,buf,chan)
+    def __init__(self,mode,buf,chan):
+        self.od = new_aubio_onsetdetection(mode,buf,chan)
     def do(self,tc,tf):
         aubio_onsetdetection_do(self.od,tc(),tf())
     def __del__(self):
@@ -93,8 +93,8 @@
         self.myfft    = cvec(bufsize,channels)
         self.pv       = pvoc(bufsize,hopsize,channels)
         if mode in ['dual'] :
-                self.myod     = onsetdetection(aubio_onset_hfc,bufsize,channels)
-                self.myod2    = onsetdetection(aubio_onset_mkl,bufsize,channels)
+                self.myod     = onsetdetection("hfc",bufsize,channels)
+                self.myod2    = onsetdetection("mkl",bufsize,channels)
                 self.myonset  = fvec(1,channels)
                 self.myonset2 = fvec(1,channels)
         else: 
--- a/src/onset/onset.c
+++ b/src/onset/onset.c
@@ -88,7 +88,7 @@
 }
 
 /* Allocate memory for an onset detection */
-aubio_onset_t * new_aubio_onset (aubio_onsetdetection_type type_onset, 
+aubio_onset_t * new_aubio_onset (char_t * onset_mode, 
     uint_t buf_size, uint_t hop_size, uint_t channels)
 {
   aubio_onset_t * o = AUBIO_NEW(aubio_onset_t);
@@ -99,11 +99,11 @@
   o->wasonset  = 0;
   o->pv = new_aubio_pvoc(buf_size, hop_size, channels);
   o->pp = new_aubio_peakpicker(o->threshold);
-  o->od = new_aubio_onsetdetection(type_onset,buf_size,channels);
+  o->od = new_aubio_onsetdetection(onset_mode,buf_size,channels);
   o->fftgrain = new_cvec(buf_size,channels);
   o->of = new_fvec(1, channels);
   /*if (usedoubled)    {
-    o2 = new_aubio_onsetdetection(type_onset2,buffer_size,channels);
+    o2 = new_aubio_onsetdetection(onset_type2,buffer_size,channels);
     onset2 = new_fvec(1 , channels);
   }*/
   return o;
--- a/src/onset/onset.h
+++ b/src/onset/onset.h
@@ -51,7 +51,7 @@
   \param channels number of channels 
 
 */
-aubio_onset_t * new_aubio_onset (aubio_onsetdetection_type type_onset, 
+aubio_onset_t * new_aubio_onset (char_t * onset_mode, 
     uint_t buf_size, uint_t hop_size, uint_t channels);
 
 /** execute onset detection
--- a/src/onset/onsetdetection.c
+++ b/src/onset/onsetdetection.c
@@ -123,9 +123,21 @@
 */
 void aubio_onsetdetection_specflux(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset);
 
+/** onsetdetection types */
+typedef enum {
+        aubio_onset_energy,         /**< energy based */          
+        aubio_onset_specdiff,       /**< spectral diff */         
+        aubio_onset_hfc,            /**< high frequency content */
+        aubio_onset_complex,        /**< complex domain */        
+        aubio_onset_phase,          /**< phase fast */            
+        aubio_onset_kl,             /**< Kullback Liebler */
+        aubio_onset_mkl,            /**< modified Kullback Liebler */
+        aubio_onset_specflux,       /**< spectral flux */
+} aubio_onsetdetection_type;
+
 /** structure to store object state */
 struct _aubio_onsetdetection_t {
-  aubio_onsetdetection_type type; /**< onset detection type */
+  aubio_onsetdetection_type onset_type; /**< onset detection type */
   /** Pointer to aubio_onsetdetection_<type> function */
   void (*funcpointer)(aubio_onsetdetection_t *o,
       cvec_t * fftgrain, fvec_t * onset);
@@ -304,11 +316,34 @@
  * depending on the choosen type, allocate memory as needed
  */
 aubio_onsetdetection_t * 
-new_aubio_onsetdetection (aubio_onsetdetection_type type, 
+new_aubio_onsetdetection (char_t * onset_mode, 
     uint_t size, uint_t channels){
   aubio_onsetdetection_t * o = AUBIO_NEW(aubio_onsetdetection_t);
   uint_t rsize = size/2+1;
-  switch(type) {
+  aubio_onsetdetection_type onset_type;
+  if (strcmp (onset_mode, "energy") == 0)
+      onset_type = aubio_onset_energy;
+  else if (strcmp (onset_mode, "specdiff") == 0)
+      onset_type = aubio_onset_specdiff;
+  else if (strcmp (onset_mode, "hfc") == 0)
+      onset_type = aubio_onset_hfc;
+  else if (strcmp (onset_mode, "complexdomain") == 0)
+      onset_type = aubio_onset_complex;
+  else if (strcmp (onset_mode, "complex") == 0)
+      onset_type = aubio_onset_complex;
+  else if (strcmp (onset_mode, "phase") == 0)
+      onset_type = aubio_onset_phase;
+  else if (strcmp (onset_mode, "mkl") == 0)
+      onset_type = aubio_onset_mkl;
+  else if (strcmp (onset_mode, "kl") == 0)
+      onset_type = aubio_onset_kl;
+  else if (strcmp (onset_mode, "specflux") == 0)
+      onset_type = aubio_onset_specflux;
+  else {
+      AUBIO_ERR("unknown onset type.\n");
+      return NULL;
+  }
+  switch(onset_type) {
     /* for both energy and hfc, only fftgrain->norm is required */
     case aubio_onset_energy: 
       break;
@@ -347,7 +382,7 @@
    * detections on the fly. this would need getting rid of the switch
    * above and always allocate all the structure */
 
-  switch(type) {
+  switch(onset_type) {
     case aubio_onset_energy:
       o->funcpointer = aubio_onsetdetection_energy;
       break;
@@ -375,12 +410,12 @@
     default:
       break;
   }
-  o->type = type;
+  o->onset_type = onset_type;
   return o;
 }
 
 void del_aubio_onsetdetection (aubio_onsetdetection_t *o){
-  switch(o->type) {
+  switch(o->onset_type) {
     /* for both energy and hfc, only fftgrain->norm is required */
     case aubio_onset_energy: 
       break;
--- a/src/onset/onsetdetection.h
+++ b/src/onset/onsetdetection.h
@@ -38,18 +38,6 @@
 extern "C" {
 #endif
 
-/** onsetdetection types */
-typedef enum {
-        aubio_onset_energy,         /**< energy based */          
-        aubio_onset_specdiff,       /**< spectral diff */         
-        aubio_onset_hfc,            /**< high frequency content */
-        aubio_onset_complex,        /**< complex domain */        
-        aubio_onset_phase,          /**< phase fast */            
-        aubio_onset_kl,             /**< Kullback Liebler */
-        aubio_onset_mkl,            /**< modified Kullback Liebler */
-        aubio_onset_specflux,       /**< spectral flux */
-} aubio_onsetdetection_type;
-
 /** onsetdetection structure */
 typedef struct _aubio_onsetdetection_t aubio_onsetdetection_t;
 /** execute onset detection function on a spectral frame 
@@ -69,7 +57,7 @@
   \param channels number of input channels
 
 */
-aubio_onsetdetection_t * new_aubio_onsetdetection(aubio_onsetdetection_type type, uint_t size, uint_t channels);
+aubio_onsetdetection_t * new_aubio_onsetdetection(char_t * onset_mode, uint_t buf_size, uint_t channels);
 /** deletion of an onset detection object
 
   \param o onset detection object as returned by new_aubio_onsetdetection()
--- a/src/tempo/tempo.c
+++ b/src/tempo/tempo.c
@@ -98,7 +98,7 @@
 }
 
 /* Allocate memory for an tempo detection */
-aubio_tempo_t * new_aubio_tempo (aubio_onsetdetection_type type_onset, 
+aubio_tempo_t * new_aubio_tempo (char_t * onset_mode, 
     uint_t buf_size, uint_t hop_size, uint_t channels)
 {
   aubio_tempo_t * o = AUBIO_NEW(aubio_tempo_t);
@@ -113,7 +113,7 @@
   o->out      = new_fvec(o->step,channels);
   o->pv       = new_aubio_pvoc(buf_size, hop_size, channels);
   o->pp       = new_aubio_peakpicker(o->threshold);
-  o->od       = new_aubio_onsetdetection(type_onset,buf_size,channels);
+  o->od       = new_aubio_onsetdetection(onset_mode,buf_size,channels);
   o->of       = new_fvec(1, channels);
   o->bt       = new_aubio_beattracking(o->winlen,channels);
   /*if (usedoubled)    {
--- a/src/tempo/tempo.h
+++ b/src/tempo/tempo.h
@@ -37,7 +37,7 @@
 typedef struct _aubio_tempo_t aubio_tempo_t;
 
 /** create tempo detection object */
-aubio_tempo_t * new_aubio_tempo (aubio_onsetdetection_type type_onset, 
+aubio_tempo_t * new_aubio_tempo (char_t * mode, 
     uint_t buf_size, uint_t hop_size, uint_t channels);
 
 /** execute tempo detection */
--- a/swig/aubio.i
+++ b/swig/aubio.i
@@ -187,17 +187,7 @@
 %#endif /* HAVE_SAMPLERATE */
 
 /* onset detection */
-typedef enum { 
-        aubio_onset_energy, 
-        aubio_onset_specdiff, 
-        aubio_onset_hfc, 
-        aubio_onset_complex, 
-        aubio_onset_phase, 
-        aubio_onset_kl, 
-        aubio_onset_mkl, 
-        aubio_onset_specflux,
-} aubio_onsetdetection_type;
-aubio_onsetdetection_t * new_aubio_onsetdetection(aubio_onsetdetection_type type, uint_t size, uint_t channels);
+aubio_onsetdetection_t * new_aubio_onsetdetection(char * onset_mode, uint_t size, uint_t channels);
 void aubio_onsetdetection_do (aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset);
 void del_aubio_onsetdetection(aubio_onsetdetection_t *o);
 
--- a/tests/src/test-onset.c
+++ b/tests/src/test-onset.c
@@ -6,7 +6,7 @@
         uint_t channels   = 1;                          /* number of channel */
         fvec_t * in       = new_fvec (win_s/4, channels); /* input buffer */
         fvec_t * out      = new_fvec (2, channels);     /* input buffer */
-        aubio_onset_t * onset  = new_aubio_onset(aubio_onset_complex, win_s, win_s/4, channels);
+        aubio_onset_t * onset  = new_aubio_onset("complex", win_s, win_s/4, channels);
         uint_t i = 0;
 
         while (i < 10) {
--- a/tests/src/test-onsetdetection.c
+++ b/tests/src/test-onsetdetection.c
@@ -11,31 +11,31 @@
 
   aubio_onsetdetection_t *o;
   
-  o = new_aubio_onsetdetection (aubio_onset_energy, win_s, channels);
+  o = new_aubio_onsetdetection ("energy", win_s, channels);
   aubio_onsetdetection_do (o, in, out);
   del_aubio_onsetdetection (o);
 
-  o = new_aubio_onsetdetection (aubio_onset_specdiff, win_s, channels);
+  o = new_aubio_onsetdetection ("energy", win_s, channels);
   aubio_onsetdetection_do (o, in, out);
   del_aubio_onsetdetection (o);
 
-  o = new_aubio_onsetdetection (aubio_onset_hfc, win_s, channels);
+  o = new_aubio_onsetdetection ("hfc", win_s, channels);
   aubio_onsetdetection_do (o, in, out);
   del_aubio_onsetdetection (o);
 
-  o = new_aubio_onsetdetection (aubio_onset_complex, win_s, channels);
+  o = new_aubio_onsetdetection ("complex", win_s, channels);
   aubio_onsetdetection_do (o, in, out);
   del_aubio_onsetdetection (o);
 
-  o = new_aubio_onsetdetection (aubio_onset_phase, win_s, channels);
+  o = new_aubio_onsetdetection ("phase", win_s, channels);
   aubio_onsetdetection_do (o, in, out);
   del_aubio_onsetdetection (o);
 
-  o = new_aubio_onsetdetection (aubio_onset_kl, win_s, channels);
+  o = new_aubio_onsetdetection ("kl", win_s, channels);
   aubio_onsetdetection_do (o, in, out);
   del_aubio_onsetdetection (o);
 
-  o = new_aubio_onsetdetection (aubio_onset_mkl, win_s, channels);
+  o = new_aubio_onsetdetection ("mkl", win_s, channels);
   aubio_onsetdetection_do (o, in, out);
   del_aubio_onsetdetection (o);
 
--- a/tests/src/test-tempo.c
+++ b/tests/src/test-tempo.c
@@ -7,7 +7,7 @@
         uint_t channels   = 1;                          /* number of channel */
         fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
         fvec_t * out      = new_fvec (2, channels);     /* input buffer */
-        aubio_tempo_t * o  = new_aubio_tempo(aubio_onset_complex, win_s, win_s/4, channels);
+        aubio_tempo_t * o  = new_aubio_tempo("complex", win_s, win_s/4, channels);
         uint_t i = 0;
 
         smpl_t curtempo, curtempoconf;