From b4f5967809d2ebb0a69d303048017cfad34927ac Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Thu, 15 Oct 2009 17:09:34 +0200 Subject: [PATCH] src/onset: use a string to set onset mode, keeping onset types enum private, update everywhere onsets are used --- examples/aubiotrack.c | 2 +- examples/utils.c | 34 +++--------------------- examples/utils.h | 3 +-- plugins/puredata/aubioonset~.c | 2 +- plugins/puredata/aubiotempo~.c | 2 +- python/aubio/aubioclass.py | 8 +++--- src/onset/onset.c | 6 ++--- src/onset/onset.h | 2 +- src/onset/onsetdetection.c | 47 ++++++++++++++++++++++++++++----- src/onset/onsetdetection.h | 14 +--------- src/tempo/tempo.c | 4 +-- src/tempo/tempo.h | 2 +- swig/aubio.i | 12 +-------- tests/src/test-onset.c | 2 +- tests/src/test-onsetdetection.c | 14 +++++----- tests/src/test-tempo.c | 2 +- 16 files changed, 70 insertions(+), 86 deletions(-) diff --git a/examples/aubiotrack.c b/examples/aubiotrack.c index 65a7a330..233b6b35 100644 --- a/examples/aubiotrack.c +++ b/examples/aubiotrack.c @@ -80,7 +80,7 @@ int main(int argc, char **argv) { 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); diff --git a/examples/utils.c b/examples/utils.c index 3800e4ca..5fc76425 100644 --- a/examples/utils.c +++ b/examples/utils.c @@ -45,8 +45,7 @@ int frames_delay = 0; /* 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 @@ uint_t isready = 0; /* badly redeclare some things */ -aubio_onsetdetection_type type_onset; smpl_t threshold; smpl_t averaging; const char *prog_name; @@ -163,29 +161,7 @@ parse_args (int argc, char **argv) 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 @@ examples_common_init (int argc, char **argv) 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); - } } diff --git a/examples/utils.h b/examples/utils.h index 4bf51204..3a857aa1 100644 --- a/examples/utils.h +++ b/examples/utils.h @@ -78,8 +78,7 @@ extern int usedoubled; /* 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; diff --git a/plugins/puredata/aubioonset~.c b/plugins/puredata/aubioonset~.c index 2906ce30..9236d4d7 100644 --- a/plugins/puredata/aubioonset~.c +++ b/plugins/puredata/aubioonset~.c @@ -87,7 +87,7 @@ static void *aubioonset_tilde_new (t_floatarg f) 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); diff --git a/plugins/puredata/aubiotempo~.c b/plugins/puredata/aubiotempo~.c index 8bc5aa44..32cd4012 100644 --- a/plugins/puredata/aubiotempo~.c +++ b/plugins/puredata/aubiotempo~.c @@ -82,7 +82,7 @@ static void *aubiotempo_tilde_new (t_floatarg f) 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); diff --git a/python/aubio/aubioclass.py b/python/aubio/aubioclass.py index 18f6ce16..6ec95ace 100644 --- a/python/aubio/aubioclass.py +++ b/python/aubio/aubioclass.py @@ -69,8 +69,8 @@ class pvoc: 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 @@ class onsetpick: 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: diff --git a/src/onset/onset.c b/src/onset/onset.c index 296aafc1..b9064699 100644 --- a/src/onset/onset.c +++ b/src/onset/onset.c @@ -88,7 +88,7 @@ void aubio_onset_set_minioi(aubio_onset_t * o, uint_t minioi) { } /* 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 @@ aubio_onset_t * new_aubio_onset (aubio_onsetdetection_type type_onset, 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; diff --git a/src/onset/onset.h b/src/onset/onset.h index 8e7e7e31..2ec8803c 100644 --- a/src/onset/onset.h +++ b/src/onset/onset.h @@ -51,7 +51,7 @@ typedef struct _aubio_onset_t aubio_onset_t; \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 diff --git a/src/onset/onsetdetection.c b/src/onset/onsetdetection.c index 62163808..d15e7e26 100644 --- a/src/onset/onsetdetection.c +++ b/src/onset/onsetdetection.c @@ -123,9 +123,21 @@ void aubio_onsetdetection_mkl(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec */ 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_ function */ void (*funcpointer)(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset); @@ -304,11 +316,34 @@ aubio_onsetdetection_do (aubio_onsetdetection_t *o, cvec_t * fftgrain, * 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 @@ new_aubio_onsetdetection (aubio_onsetdetection_type type, * 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 @@ new_aubio_onsetdetection (aubio_onsetdetection_type type, 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; diff --git a/src/onset/onsetdetection.h b/src/onset/onsetdetection.h index 978005a1..a1d7ec41 100644 --- 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 @@ void aubio_onsetdetection_do (aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec \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() diff --git a/src/tempo/tempo.c b/src/tempo/tempo.c index 2d949c0d..87e44042 100644 --- a/src/tempo/tempo.c +++ b/src/tempo/tempo.c @@ -98,7 +98,7 @@ void aubio_tempo_set_threshold(aubio_tempo_t * o, smpl_t threshold) { } /* 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 @@ aubio_tempo_t * new_aubio_tempo (aubio_onsetdetection_type type_onset, 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) { diff --git a/src/tempo/tempo.h b/src/tempo/tempo.h index 0c3f7721..ed339167 100644 --- a/src/tempo/tempo.h +++ b/src/tempo/tempo.h @@ -37,7 +37,7 @@ extern "C" { 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 */ diff --git a/swig/aubio.i b/swig/aubio.i index 984c99a2..8842cce5 100644 --- a/swig/aubio.i +++ b/swig/aubio.i @@ -187,17 +187,7 @@ extern void del_aubio_resampler(aubio_resampler_t *s); %#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); diff --git a/tests/src/test-onset.c b/tests/src/test-onset.c index 370cd03b..93ded23e 100644 --- a/tests/src/test-onset.c +++ b/tests/src/test-onset.c @@ -6,7 +6,7 @@ int main(){ 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) { diff --git a/tests/src/test-onsetdetection.c b/tests/src/test-onsetdetection.c index 64a780e6..77ef7a8f 100644 --- a/tests/src/test-onsetdetection.c +++ b/tests/src/test-onsetdetection.c @@ -11,31 +11,31 @@ main () 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); diff --git a/tests/src/test-tempo.c b/tests/src/test-tempo.c index 0c1ee25f..fb4d2f3c 100644 --- a/tests/src/test-tempo.c +++ b/tests/src/test-tempo.c @@ -7,7 +7,7 @@ int main(){ 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; -- 2.26.2