From 5cf415f92b76a68cf282426ab69502f2cd029901 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Tue, 9 Aug 2005 18:35:14 +0000 Subject: [PATCH] protected onset enumerators, factorise python check_modes --- examples/utils.c | 20 +++++++++++------ plugins/puredata/aubioonset~.c | 2 +- python/aubio/aubioclass.py | 41 ++++++++++++++++++++++++++++++++-- python/aubiocut | 24 +------------------- python/aubiopitch | 14 ++---------- src/onsetdetection.c | 38 +++++++++++++++---------------- src/onsetdetection.h | 14 ++++++------ swig/aubio.i | 14 ++++++++++-- 8 files changed, 94 insertions(+), 73 deletions(-) diff --git a/examples/utils.c b/examples/utils.c index 6ac948fa..7c8abe0b 100644 --- a/examples/utils.c +++ b/examples/utils.c @@ -29,8 +29,8 @@ int usedoubled = 1; /* energy,specdiff,hfc,complexdomain,phase */ -aubio_onsetdetection_type type_onset = kl; -aubio_onsetdetection_type type_onset2 = complexdomain; +aubio_onsetdetection_type type_onset = aubio_onset_kl; +aubio_onsetdetection_type type_onset2 = aubio_onset_complex; smpl_t threshold = 0.3; smpl_t threshold2 = -90.; uint_t buffer_size = 512; //1024; @@ -139,15 +139,21 @@ int parse_args (int argc, char **argv) { break; case 'O': /*onset type*/ if (strcmp(optarg,"energy") == 0) - type_onset = energy; + type_onset = aubio_onset_energy; else if (strcmp(optarg,"specdiff") == 0) - type_onset = specdiff; + type_onset = aubio_onset_specdiff; else if (strcmp(optarg,"hfc") == 0) - type_onset = hfc; + type_onset = aubio_onset_hfc; else if (strcmp(optarg,"complexdomain") == 0) - type_onset = complexdomain; + type_onset = aubio_onset_complex; + else if (strcmp(optarg,"complex") == 0) + type_onset = aubio_onset_complex; else if (strcmp(optarg,"phase") == 0) - type_onset = phase; + 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 { debug("could not get onset type.\n"); abort(); diff --git a/plugins/puredata/aubioonset~.c b/plugins/puredata/aubioonset~.c index 16b001f6..b0e92d39 100644 --- a/plugins/puredata/aubioonset~.c +++ b/plugins/puredata/aubioonset~.c @@ -70,7 +70,7 @@ static void *aubioonset_tilde_new (t_floatarg f) x->bufsize = 1024; x->hopsize = x->bufsize / 2; - x->o = new_aubio_onsetdetection(complexdomain, x->bufsize, 1); + x->o = new_aubio_onsetdetection(aubio_onset_complex, x->bufsize, 1); x->vec = (fvec_t *)new_fvec(x->hopsize,1); x->pv = new_aubio_pvoc(x->bufsize, x->hopsize, 1); x->fftgrain = new_cvec(x->bufsize,1); diff --git a/python/aubio/aubioclass.py b/python/aubio/aubioclass.py index 9a400a14..b39a7a9b 100644 --- a/python/aubio/aubioclass.py +++ b/python/aubio/aubioclass.py @@ -79,8 +79,8 @@ class onsetpick: self.myfft = cvec(bufsize,channels) self.pv = pvoc(bufsize,hopsize,channels) if mode in ['dual'] : - self.myod = onsetdetection(hfc,bufsize,channels) - self.myod2 = onsetdetection(complexdomain,bufsize,channels) + self.myod = onsetdetection(aubio_onset_hfc,bufsize,channels) + self.myod2 = onsetdetection(aubio_onset_complex,bufsize,channels) self.myonset = fvec(1,channels) self.myonset2 = fvec(1,channels) else: @@ -105,6 +105,43 @@ class onsetpick: else: self.myonset.set(0.,0,0) return self.pp.do(self.myonset),self.myonset.get(0,0) +def check_onset_mode(option, opt, value, parser): + nvalue = parser.rargs[0] + if nvalue == 'complexdomain' or nvalue == 'complex' : + setattr(parser.values, option.dest, aubio_onset_complex) + elif nvalue == 'hfc' : + setattr(parser.values, option.dest, aubio_onset_hfc) + elif nvalue == 'phase' : + setattr(parser.values, option.dest, aubio_onset_phase) + elif nvalue == 'specdiff' : + setattr(parser.values, option.dest, aubio_onset_specdiff) + elif nvalue == 'energy' : + setattr(parser.values, option.dest, aubio_onset_energy) + elif nvalue == 'kl' : + setattr(parser.values, option.dest, aubio_onset_kl) + elif nvalue == 'mkl' : + setattr(parser.values, option.dest, aubio_onset_mkl) + elif nvalue == 'dual' : + setattr(parser.values, option.dest, 'dual') + else: + print "unknown detection function selected\n", usage + sys.exit(1) + +def check_pitch_mode(option, opt, value, parser): + nvalue = parser.rargs[0] + if nvalue == 'mcomb' : + setattr(parser.values, option.dest, aubio_pitch_mcomb) + elif nvalue == 'yin' : + setattr(parser.values, option.dest, aubio_pitch_yin) + elif nvalue == 'fcomb' : + setattr(parser.values, option.dest, aubio_pitch_fcomb) + elif nvalue == 'schmitt' : + setattr(parser.values, option.dest, aubio_pitch_schmitt) + else: + print "unknown detection function selected\n", usage + sys.exit(1) + + def getonsets(filein,threshold=0.2,silence=-70.,bufsize=1024,hopsize=512, mode='dual',localmin=False,storefunc=False,derivate=False): frameread = 0 diff --git a/python/aubiocut b/python/aubiocut index 45b59099..9683d314 100755 --- a/python/aubiocut +++ b/python/aubiocut @@ -9,28 +9,6 @@ from aubio.aubioclass import * usage = "usage: %s [options] -i soundfile" % sys.argv[0] -def check_mode(option, opt, value, parser): - nvalue = parser.rargs[0] - if nvalue == 'complexdomain' : - setattr(parser.values, option.dest, complexdomain) - elif nvalue == 'hfc' : - setattr(parser.values, option.dest, hfc) - elif nvalue == 'phase' : - setattr(parser.values, option.dest, phase) - elif nvalue == 'specdiff' : - setattr(parser.values, option.dest, specdiff) - elif nvalue == 'energy' : - setattr(parser.values, option.dest, energy) - elif nvalue == 'kl' : - setattr(parser.values, option.dest, kl) - elif nvalue == 'mkl' : - setattr(parser.values, option.dest, mkl) - elif nvalue == 'dual' : - setattr(parser.values, option.dest, 'dual') - else: - print "unknown detection function selected\n", usage - sys.exit(1) - def parse_args(): from optparse import OptionParser parser = OptionParser(usage=usage) @@ -38,7 +16,7 @@ def parse_args(): action="store", dest="filename", help="input sound file") parser.add_option("-m","--mode", action="callback", - callback=check_mode, dest="mode", default='dual', + callback=check_onset_mode, dest="mode", default='dual', help="onset detection mode [default=dual] \ complexdomain|hfc|phase|specdiff|energy|kl|mkl|dual") parser.add_option("-B","--bufsize", diff --git a/python/aubiopitch b/python/aubiopitch index 5413d78b..28bf30ac 100755 --- a/python/aubiopitch +++ b/python/aubiopitch @@ -10,17 +10,6 @@ from aubio.aubioclass import * usage = "usage: %s [options] -i soundfile" % sys.argv[0] -def check_mode(option, opt, value, parser): - nvalue = parser.rargs[0] - if nvalue == 'mcomb' : - setattr(parser.values, option.dest, aubio_pitch_mcomb) - elif nvalue == 'yin' : - setattr(parser.values, option.dest, aubio_pitch_yin) - elif nvalue == 'fcomb' : - setattr(parser.values, option.dest, aubio_pitch_fcomb) - elif nvalue == 'schmitt' : - setattr(parser.values, option.dest, aubio_pitch_schmitt) - def parse_args(): from optparse import OptionParser @@ -29,7 +18,8 @@ def parse_args(): action="store", dest="filename", help="input sound file") parser.add_option("-m","--mode", action="callback", - callback=check_mode, dest="mode", default=aubio_pitch_mcomb, + callback=check_pitch_mode, dest="mode", + default=aubio_pitch_mcomb, help="pitch detection mode [default=mcomb] \ mcomb|yin|fcomb|schmitt") parser.add_option("-B","--bufsize", diff --git a/src/onsetdetection.c b/src/onsetdetection.c index 6111e8e7..db40f7a1 100644 --- a/src/onsetdetection.c +++ b/src/onsetdetection.c @@ -207,12 +207,12 @@ aubio_onsetdetection_alloc (aubio_onsetdetection_type type, uint_t rsize = size/2+1; switch(type) { /* for both energy and hfc, only fftgrain->norm is required */ - case energy: + case aubio_onset_energy: break; - case hfc: + case aubio_onset_hfc: break; /* the other approaches will need some more memory spaces */ - case complexdomain: + case aubio_onset_complex: o->oldmag = new_fvec(rsize,channels); /** bug: must be complex array */ o->meas = AUBIO_ARRAY(fft_data_t,size); @@ -220,23 +220,23 @@ aubio_onsetdetection_alloc (aubio_onsetdetection_type type, o->theta1 = new_fvec(rsize,channels); o->theta2 = new_fvec(rsize,channels); break; - case phase: + case aubio_onset_phase: o->dev1 = new_fvec(rsize,channels); o->theta1 = new_fvec(rsize,channels); o->theta2 = new_fvec(rsize,channels); o->histog = new_aubio_hist(0.0f, PI, 10, channels); o->threshold = 0.1; break; - case specdiff: + case aubio_onset_specdiff: o->oldmag = new_fvec(rsize,channels); o->dev1 = new_fvec(rsize,channels); o->histog = new_aubio_hist(0.0f, PI, 10, channels); o->threshold = 0.1; break; - case kl: + case aubio_onset_kl: o->oldmag = new_fvec(rsize,channels); break; - case mkl: + case aubio_onset_mkl: o->oldmag = new_fvec(rsize,channels); break; default: @@ -248,25 +248,25 @@ aubio_onsetdetection_alloc (aubio_onsetdetection_type type, * above and always allocate all the structure */ switch(type) { - case energy: + case aubio_onset_energy: o->funcpointer = aubio_onsetdetection_energy; break; - case hfc: + case aubio_onset_hfc: o->funcpointer = aubio_onsetdetection_hfc; break; - case complexdomain: + case aubio_onset_complex: o->funcpointer = aubio_onsetdetection_complex; break; - case phase: + case aubio_onset_phase: o->funcpointer = aubio_onsetdetection_phase; break; - case specdiff: + case aubio_onset_specdiff: o->funcpointer = aubio_onsetdetection_specdiff; break; - case kl: + case aubio_onset_kl: o->funcpointer = aubio_onsetdetection_kl; break; - case mkl: + case aubio_onset_mkl: o->funcpointer = aubio_onsetdetection_mkl; break; default: @@ -280,25 +280,25 @@ void aubio_onsetdetection_free (aubio_onsetdetection_t *o){ switch(o->type) { /* for both energy and hfc, only fftgrain->norm is required */ - case energy: + case aubio_onset_energy: break; - case hfc: + case aubio_onset_hfc: break; /* the other approaches will need some more memory spaces */ - case complexdomain: + case aubio_onset_complex: AUBIO_FREE(o->meas); del_fvec(o->oldmag); del_fvec(o->dev1); del_fvec(o->theta1); del_fvec(o->theta2); break; - case phase: + case aubio_onset_phase: del_fvec(o->dev1); del_fvec(o->theta1); del_fvec(o->theta2); del_aubio_hist(o->histog); break; - case specdiff: + case aubio_onset_specdiff: del_fvec(o->oldmag); del_fvec(o->dev1); del_aubio_hist(o->histog); diff --git a/src/onsetdetection.h b/src/onsetdetection.h index a27cb7e4..3f20a459 100644 --- a/src/onsetdetection.h +++ b/src/onsetdetection.h @@ -49,13 +49,13 @@ extern "C" { /** onsetdetection types */ typedef enum { - energy, /**< energy based */ - specdiff, /**< spectral diff */ - hfc, /**< high frequency content */ - complexdomain, /**< complex domain */ - phase, /**< phase fast */ - kl, /**< Kullback Liebler (Hainsworth et al., Onset detection in musical audio signals) */ - mkl /**< modified Kullback Liebler (Hainsworth et al., Onset detection in musical audio signals) */ + 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 (Hainsworth et al., Onset detection in musical audio signals) */ + aubio_onset_mkl /**< modified Kullback Liebler (Hainsworth et al., Onset detection in musical audio signals) */ } aubio_onsetdetection_type; /** onsetdetection structure */ diff --git a/swig/aubio.i b/swig/aubio.i index 5fb3f26e..e9b6aeb8 100644 --- a/swig/aubio.i +++ b/swig/aubio.i @@ -138,17 +138,27 @@ extern uint_t aubio_resampler_process(aubio_resampler_t *s, fvec_t * input, fve extern void del_aubio_resampler(aubio_resampler_t *s); /* onset detection */ -typedef enum { energy, specdiff, hfc, complexdomain, phase, kl, mkl } aubio_onsetdetection_type; +typedef enum { + aubio_onset_energy, + aubio_onset_specdiff, + aubio_onset_hfc, + aubio_onset_complex, + aubio_onset_phase, + aubio_onset_kl, + aubio_onset_mkl +} aubio_onsetdetection_type; aubio_onsetdetection_t * new_aubio_onsetdetection(aubio_onsetdetection_type type, uint_t size, uint_t channels); void aubio_onsetdetection(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset); void aubio_onsetdetection_free(aubio_onsetdetection_t *o); /* should these still be exposed ? */ void aubio_onsetdetection_energy (aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset); -void aubio_onsetdetection_hfc (aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset); +void aubio_onsetdetection_hfc (aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset); void aubio_onsetdetection_complex (aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset); void aubio_onsetdetection_phase (aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset); void aubio_onsetdetection_specdiff(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset); +void aubio_onsetdetection_kl (aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset); +void aubio_onsetdetection_mkl (aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset); /* pvoc */ aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s, uint_t channels); -- 2.26.2