protected onset enumerators, factorise python check_modes
authorPaul Brossier <piem@altern.org>
Tue, 9 Aug 2005 18:35:14 +0000 (18:35 +0000)
committerPaul Brossier <piem@altern.org>
Tue, 9 Aug 2005 18:35:14 +0000 (18:35 +0000)
examples/utils.c
plugins/puredata/aubioonset~.c
python/aubio/aubioclass.py
python/aubiocut
python/aubiopitch
src/onsetdetection.c
src/onsetdetection.h
swig/aubio.i

index 6ac948faeeb038ef43ea6945e935457379a4bf1d..7c8abe0b1096f77188d08a80a3b271e0a42e41d5 100644 (file)
@@ -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();
index 16b001f6389f4265d0ac07d4ab2e32816a85bac8..b0e92d39fd02af7d0618e6d836e78980e0f380dd 100644 (file)
@@ -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);
index 9a400a140620fa1a3144e39aabe557839a591197..b39a7a9b8a9cf4acb96f8d1ea5439d62b0045d1a 100644 (file)
@@ -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
index 45b5909961177e32c98d146a497575f801af3d13..9683d31475271a8de28c13e0fc8d5aed2d0bb688 100755 (executable)
@@ -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",
index 5413d78b5446a38ff249d2e6c5629c8f025e0fb0..28bf30ac20de0878b8755d69b103c4ecb39cf860 100755 (executable)
@@ -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",
index 6111e8e7729c1e18cb39c122812385d1a62afe83..db40f7a167800c34bd58d458e45a249c45d5478d 100644 (file)
@@ -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);
index a27cb7e43c749e144cde27f1c3fb63d38a4b7098..3f20a4594438aec56f22d0627b8fb7b2d71ebe3e 100644 (file)
@@ -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 */
index 5fb3f26e94686b7ce7aea5e2dc9bf7091d32b9c3..e9b6aeb82ac3ae7f6f29d676a782750578640186 100644 (file)
@@ -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);