ref: 5cf415f92b76a68cf282426ab69502f2cd029901
parent: a29ad469acef958f7657a3757cfc43a0de6fd7d1
author: Paul Brossier <piem@altern.org>
date: Tue Aug 9 14:35:14 EDT 2005
protected onset enumerators, factorise python check_modes
--- a/examples/utils.c
+++ b/examples/utils.c
@@ -29,8 +29,8 @@
/* 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 @@
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();
--- a/plugins/puredata/aubioonset~.c
+++ b/plugins/puredata/aubioonset~.c
@@ -70,7 +70,7 @@
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);
--- a/python/aubio/aubioclass.py
+++ b/python/aubio/aubioclass.py
@@ -79,8 +79,8 @@
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:
@@ -104,6 +104,43 @@
if dval > 0: self.myonset.set(dval,0,0)
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):
--- a/python/aubiocut
+++ b/python/aubiocut
@@ -9,28 +9,6 @@
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 @@
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",
--- a/python/aubiopitch
+++ b/python/aubiopitch
@@ -10,18 +10,7 @@
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
parser = OptionParser(usage=usage)
@@ -29,7 +18,8 @@
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",
--- a/src/onsetdetection.c
+++ b/src/onsetdetection.c
@@ -207,12 +207,12 @@
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,7 +220,7 @@
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);
@@ -227,16 +227,16 @@
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 @@
* 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,12 +280,12 @@
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);
@@ -292,13 +292,13 @@
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);
--- a/src/onsetdetection.h
+++ b/src/onsetdetection.h
@@ -49,13 +49,13 @@
/** 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 */
--- a/swig/aubio.i
+++ b/swig/aubio.i
@@ -138,7 +138,15 @@
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);
@@ -145,10 +153,12 @@
/* 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);