Changeset fe163ad


Ignore:
Timestamp:
Oct 15, 2009, 6:54:23 PM (15 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
515c7b2
Parents:
cd77c15
Message:

src/pitch: use a string to set pitch method, add a new function to set pitch unit, keep pitch enums private, update pitch methods where they are used

Files:
14 edited

Legend:

Unmodified
Added
Removed
  • examples/aubionotes.c

    rcd77c15 rfe163ad  
    4040      aubio_pvoc_do (pv,ibuf, fftgrain);
    4141      aubio_onsetdetection_do(o,fftgrain, onset);
    42       if (usedoubled) {
    43         aubio_onsetdetection_do(o2,fftgrain, onset2);
    44         onset->data[0][0] *= onset2->data[0][0];
    45       }
    4642      isonset = aubio_peakpicker_do(parms, onset);
    4743     
  • examples/aubioonset.c

    rcd77c15 rfe163ad  
    4040      aubio_pvoc_do (pv,ibuf, fftgrain);
    4141      aubio_onsetdetection_do (o,fftgrain, onset);
    42       if (usedoubled) {
    43         aubio_onsetdetection_do (o2,fftgrain, onset2);
    44         onset->data[0][0] *= onset2->data[0][0];
    45       }
    4642      isonset = aubio_peakpicker_do(parms, onset);
    4743      if (isonset) {
  • examples/utils.c

    rcd77c15 rfe163ad  
    6565fvec_t *woodblock;
    6666aubio_onsetdetection_t *o;
    67 aubio_onsetdetection_t *o2;
    6867fvec_t *onset;
    6968fvec_t *onset2;
     
    7574smpl_t pitch = 0.;
    7675aubio_pitchdetection_t *pitchdet;
    77 aubio_pitchdetection_type type_pitch = aubio_pitch_yinfft;      // aubio_pitch_mcomb
    78 aubio_pitchdetection_mode mode_pitch = aubio_pitchm_freq;
     76char_t * pitch_unit = "default";
     77char_t * pitch_mode = "default";
    7978uint_t median = 6;
    8079
     
    177176        break;
    178177      case 'p':
    179         if (strcmp (optarg, "mcomb") == 0)
    180           type_pitch = aubio_pitch_mcomb;
    181         else if (strcmp (optarg, "yinfft") == 0)
    182           type_pitch = aubio_pitch_yin;
    183         else if (strcmp (optarg, "yin") == 0)
    184           type_pitch = aubio_pitch_yin;
    185         else if (strcmp (optarg, "schmitt") == 0)
    186           type_pitch = aubio_pitch_schmitt;
    187         else if (strcmp (optarg, "fcomb") == 0)
    188           type_pitch = aubio_pitch_fcomb;
    189         else {
    190           errmsg ("unknown pitch type.\n");
    191           abort ();
    192         }
     178        pitch_mode = optarg;
    193179        break;
    194180      case 'a':
     
    294280
    295281  if (usepitch) {
    296     pitchdet = new_aubio_pitchdetection (buffer_size * 4,
    297         overlap_size, channels, samplerate, type_pitch, mode_pitch);
     282    pitchdet = new_aubio_pitchdetection (pitch_mode, buffer_size * 4,
     283        overlap_size, channels, samplerate);
    298284    aubio_pitchdetection_set_tolerance (pitchdet, 0.7);
    299285    pitch_obuf = new_fvec (1, channels);
     
    325311    }
    326312    del_fvec (pitch_obuf);
    327   }
    328   if (usedoubled) {
    329     del_aubio_onsetdetection (o2);
    330     del_fvec (onset2);
    331313  }
    332314  del_aubio_onsetdetection (o);
  • examples/utils.h

    rcd77c15 rfe163ad  
    108108extern smpl_t pitch;
    109109extern aubio_pitchdetection_t *pitchdet;
    110 extern aubio_pitchdetection_type mode;
    111110extern uint_t median;
    112111
  • plugins/puredata/aubiopitch~.c

    rcd77c15 rfe163ad  
    1313
    1414char aubiopitch_version[] = "aubiopitch~ version 0.1";
    15 
    16 aubio_pitchdetection_type type_pitch = aubio_pitch_yinfft;
    17 aubio_pitchdetection_mode mode_pitch = aubio_pitchm_freq;
    1815
    1916static t_class *aubiopitch_tilde_class;
     
    7976        x->hopsize   = x->bufsize / 2;
    8077
    81         if (strcmp(s->s_name,"mcomb") == 0)
    82                 type_pitch = aubio_pitch_mcomb;
    83         else if (strcmp(s->s_name,"yinfft") == 0)
    84                 type_pitch = aubio_pitch_yin;
    85         else if (strcmp(s->s_name,"yin") == 0)
    86                 type_pitch = aubio_pitch_yin;
    87         else if (strcmp(s->s_name,"schmitt") == 0)
    88                 type_pitch = aubio_pitch_schmitt;
    89         else if (strcmp(s->s_name,"fcomb") == 0)
    90                 type_pitch = aubio_pitch_fcomb;
    91         else {
    92                 post("unknown pitch type, using default.\n");
    93         }
    94 
    9578        //FIXME: get the real samplerate
    96         x->o = new_aubio_pitchdetection(x->bufsize,
    97                     x->hopsize, 1, 44100., type_pitch, mode_pitch);
     79    x->o = new_aubio_pitchdetection(s->s_name, x->bufsize,
     80            x->hopsize, 1, 44100.);
    9881        aubio_pitchdetection_set_tolerance (x->o, 0.7);
    9982        x->vec = (fvec_t *)new_fvec(x->hopsize,1);
  • python/aubio/aubioclass.py

    rcd77c15 rfe163ad  
    125125
    126126class pitchdetection:
    127     def __init__(self,mode=aubio_pitch_mcomb,bufsize=2048,hopsize=1024,
    128         channels=1,samplerate=44100.,omode=aubio_pitchm_freq,tolerance=0.1):
    129         self.pitchp = new_aubio_pitchdetection(bufsize,hopsize,channels,
    130                 samplerate,mode,omode)
     127    def __init__(self,mode="mcomb",bufsize=2048,hopsize=1024,
     128        channels=1,samplerate=44100.,omode="freq",tolerance=0.1):
     129        self.pitchp = new_aubio_pitchdetection(mode,bufsize,hopsize,channels,
     130            samplerate)
    131131        self.mypitch = fvec(1, channels)
     132        aubio_pitchdetection_set_unit(self.pitchp,omode)
    132133        aubio_pitchdetection_set_tolerance(self.pitchp,tolerance)
    133134        #self.filt     = filter(srate,"adsgn")
  • python/aubio/task/params.py

    rcd77c15 rfe163ad  
    1 from aubio.aubioclass import aubio_pitchm_freq
    21
    32class taskparams(object):
     
    3029                self.pitchdelay = -0.5
    3130                self.dcthreshold = -1.
    32                 self.omode = aubio_pitchm_freq
     31                self.omode = "freq"
    3332                self.verbose   = False
    3433
  • python/aubio/task/pitch.py

    rcd77c15 rfe163ad  
    1414                else:
    1515                        tolerance = 0.
    16                 self.pitchdet   = pitchdetection(mode=get_pitch_mode(self.params.pitchmode),
     16                self.pitchdet   = pitchdetection(mode=self.params.pitchmode,
    1717                        bufsize=self.params.bufsize,
    1818                        hopsize=self.params.hopsize,
  • python/aubio/task/utils.py

    rcd77c15 rfe163ad  
    2626                 sys.exit(1)
    2727
    28 def get_pitch_mode(nvalue):
    29         """ utility function to convert a string to aubio_pitchdetection_type """
    30         if   nvalue == 'mcomb'  :
    31                  return aubio_pitch_mcomb
    32         elif nvalue == 'yin'    :
    33                  return aubio_pitch_yin
    34         elif nvalue == 'fcomb'  :
    35                  return aubio_pitch_fcomb
    36         elif nvalue == 'schmitt':
    37                  return aubio_pitch_schmitt
    38         elif nvalue == 'yinfft':
    39                  return aubio_pitch_yinfft
    40         else:
    41                  import sys
    42                  print "error: unknown pitch detection function selected"
    43                  sys.exit(1)
    44 
    4528def check_onset_mode(option, opt, value, parser):
    4629        """ wrapper function to convert a list of modes to
     
    5942                val.append(get_pitch_mode(nvalue))
    6043                setattr(parser.values, option.dest, val)
    61 
    62 def check_pitchm_mode(option, opt, value, parser):
    63         """ utility function to convert a string to aubio_pitchdetection_mode """
    64         nvalue = parser.rargs[0]
    65         if   nvalue == 'freq'  :
    66                  setattr(parser.values, option.dest, aubio_pitchm_freq)
    67         elif nvalue == 'midi'  :
    68                  setattr(parser.values, option.dest, aubio_pitchm_midi)
    69         elif nvalue == 'cent'  :
    70                  setattr(parser.values, option.dest, aubio_pitchm_cent)
    71         elif nvalue == 'bin'   :
    72                  setattr(parser.values, option.dest, aubio_pitchm_bin)
    73         else:
    74                  import sys
    75                  print "error: unknown pitch detection output selected"
    76                  sys.exit(1)
    77 
    78 
  • python/aubiopitch

    rcd77c15 rfe163ad  
    1818      help="input sound file")
    1919  parser.add_option("-m","--mode",
    20       action="store", dest="mode", default='mcomb',
     20      action="store", dest="mode", default='yinfft',
    2121      help="pitch detection mode [default=mcomb] \
    2222      mcomb|yin|fcomb|schmitt")
    23   parser.add_option("-u","--units", action="callback",
    24       callback=check_pitchm_mode, dest="omode",
    25       default=aubio_pitchm_freq,
     23  parser.add_option("-u","--units",
     24      action="store", dest="omode", default="freq",
    2625      help="output pitch in units [default=Hz] \
    2726      freq|midi|cent|bin")
     
    7877  (options, args) = parser.parse_args()
    7978  if not options.bufsize:
    80     if options.mode == aubio_pitch_yin:     options.bufsize = 1024
    81     if options.mode == aubio_pitch_schmitt: options.bufsize = 2048
    82     if options.mode == aubio_pitch_mcomb:   options.bufsize = 4096
    83     if options.mode == aubio_pitch_fcomb:   options.bufsize = 4096
     79    if options.mode == "yin":     options.bufsize = 1024
     80    if options.mode == "schmitt": options.bufsize = 2048
     81    if options.mode == "mcomb":   options.bufsize = 4096
     82    if options.mode == "fcomb":   options.bufsize = 4096
    8483    else: options.bufsize = 2048
    8584  if not options.hopsize:
     
    106105if options.pitchmax:  params.pitchmax    = int(options.pitchmax)
    107106if options.pitchmin:  params.pitchmin    = int(options.pitchmin)
    108 if options.omode:     params.omode       = int(options.omode)
    109107#mintol     = float(options.mintol)*step
    110108# default take back system delay
  • src/pitch/pitchdetection.c

    rcd77c15 rfe163ad  
    3131#include "pitch/pitchyinfft.h"
    3232#include "pitch/pitchdetection.h"
     33
     34/** pitch detection algorithm */
     35typedef enum {
     36  aubio_pitch_yin,     /**< YIN algorithm */
     37  aubio_pitch_mcomb,   /**< Multi-comb filter */
     38  aubio_pitch_schmitt, /**< Schmitt trigger */
     39  aubio_pitch_fcomb,   /**< Fast comb filter */
     40  aubio_pitch_yinfft,   /**< Spectral YIN */
     41  aubio_pitch_default = aubio_pitch_yinfft, /**< the one used when "default" is asked */
     42} aubio_pitchdetection_type;
     43
     44/** pitch detection output mode */
     45typedef enum {
     46  aubio_pitchm_freq,   /**< Frequency (Hz) */
     47  aubio_pitchm_midi,   /**< MIDI note (0.,127) */
     48  aubio_pitchm_cent,   /**< Cent */
     49  aubio_pitchm_bin,    /**< Frequency bin (0,bufsize) */
     50  aubio_pitchm_default = aubio_pitchm_freq, /**< the one used when "default" is asked */
     51} aubio_pitchdetection_mode;
    3352
    3453typedef void (*aubio_pitchdetection_func_t)
     
    81100}
    82101
    83 aubio_pitchdetection_t * new_aubio_pitchdetection(uint_t bufsize,
    84     uint_t hopsize,
    85     uint_t channels,
    86     uint_t samplerate,
    87     aubio_pitchdetection_type type,
    88     aubio_pitchdetection_mode mode)
     102aubio_pitchdetection_t *
     103new_aubio_pitchdetection (char_t * pitch_mode,
     104    uint_t bufsize, uint_t hopsize, uint_t channels, uint_t samplerate)
    89105{
    90106  aubio_pitchdetection_t *p = AUBIO_NEW(aubio_pitchdetection_t);
     107  aubio_pitchdetection_type pitch_type;
     108  if (strcmp (pitch_mode, "mcomb") == 0)
     109      pitch_type = aubio_pitch_mcomb;
     110  else if (strcmp (pitch_mode, "yinfft") == 0)
     111      pitch_type = aubio_pitch_yin;
     112  else if (strcmp (pitch_mode, "yin") == 0)
     113      pitch_type = aubio_pitch_yin;
     114  else if (strcmp (pitch_mode, "schmitt") == 0)
     115      pitch_type = aubio_pitch_schmitt;
     116  else if (strcmp (pitch_mode, "fcomb") == 0)
     117      pitch_type = aubio_pitch_fcomb;
     118  else if (strcmp (pitch_mode, "default") == 0)
     119      pitch_type = aubio_pitch_default;
     120  else {
     121      AUBIO_ERR ("unknown pitch detection method %s, using default.\n", pitch_mode);
     122      pitch_type = aubio_pitch_default;
     123      return NULL;
     124  }
    91125  p->srate = samplerate;
    92   p->type = type;
    93   p->mode = mode;
     126  p->type = pitch_type;
     127  aubio_pitchdetection_set_unit (p, "default");
    94128  p->bufsize = bufsize;
    95129  switch(p->type) {
     
    126160      break;
    127161  }
    128   switch(p->mode) {
    129     case aubio_pitchm_freq:
    130       p->freqconv = freqconvpass;
    131       break;
    132     case aubio_pitchm_midi:
    133       p->freqconv = freqconvmidi;
    134       break;
    135     case aubio_pitchm_cent:
    136       /* bug: not implemented */
    137       p->freqconv = freqconvmidi;
    138       break;
    139     case aubio_pitchm_bin:
    140       p->freqconv = freqconvbin;
    141       break;
    142     default:
    143       break;
    144   }
    145162  return p;
    146163}
     
    189206    }
    190207  }
     208}
     209
     210uint_t aubio_pitchdetection_set_unit (aubio_pitchdetection_t *p, char_t * pitch_unit) {
     211  aubio_pitchdetection_mode pitch_mode;
     212  if (strcmp (pitch_unit, "freq") == 0)
     213      pitch_mode = aubio_pitchm_freq;
     214  else if (strcmp (pitch_unit, "midi") == 0)
     215      pitch_mode = aubio_pitchm_midi;
     216  else if (strcmp (pitch_unit, "cent") == 0)
     217      pitch_mode = aubio_pitchm_cent;
     218  else if (strcmp (pitch_unit, "bin") == 0)
     219      pitch_mode = aubio_pitchm_bin;
     220  else if (strcmp (pitch_unit, "default") == 0)
     221      pitch_mode = aubio_pitchm_default;
     222  else {
     223      AUBIO_ERR ("unknown pitch detection unit %s, using default\n", pitch_unit);
     224      pitch_mode = aubio_pitchm_default;
     225  }
     226  p->mode = pitch_mode;
     227  switch(p->mode) {
     228    case aubio_pitchm_freq:
     229      p->freqconv = freqconvpass;
     230      break;
     231    case aubio_pitchm_midi:
     232      p->freqconv = freqconvmidi;
     233      break;
     234    case aubio_pitchm_cent:
     235      /* bug: not implemented */
     236      p->freqconv = freqconvmidi;
     237      break;
     238    case aubio_pitchm_bin:
     239      p->freqconv = freqconvbin;
     240      break;
     241    default:
     242      break;
     243  }
     244  return 0;
    191245}
    192246
  • src/pitch/pitchdetection.h

    rcd77c15 rfe163ad  
    3232
    3333*/
    34 
    35 /** pitch detection algorithm */
    36 typedef enum {
    37   aubio_pitch_yin,     /**< YIN algorithm */
    38   aubio_pitch_mcomb,   /**< Multi-comb filter */
    39   aubio_pitch_schmitt, /**< Schmitt trigger */
    40   aubio_pitch_fcomb,   /**< Fast comb filter */
    41   aubio_pitch_yinfft   /**< Spectral YIN */
    42 } aubio_pitchdetection_type;
    43 
    44 /** pitch detection output mode */
    45 typedef enum {
    46   aubio_pitchm_freq,   /**< Frequency (Hz) */
    47   aubio_pitchm_midi,   /**< MIDI note (0.,127) */
    48   aubio_pitchm_cent,   /**< Cent */
    49   aubio_pitchm_bin     /**< Frequency bin (0,bufsize) */
    50 } aubio_pitchdetection_mode;
    5134
    5235/** pitch detection object */
     
    8568
    8669*/
    87 aubio_pitchdetection_t * new_aubio_pitchdetection(uint_t bufsize,
    88     uint_t hopsize,
    89     uint_t channels,
    90     uint_t samplerate,
    91     aubio_pitchdetection_type pitch_type,
    92     aubio_pitchdetection_mode pitch_mode);
     70aubio_pitchdetection_t *new_aubio_pitchdetection (char_t * pitch_mode,
     71    uint_t bufsize, uint_t hopsize, uint_t channels, uint_t samplerate);
     72
     73/** set the output unit of the pitch detection object */
     74uint_t aubio_pitchdetection_set_unit (aubio_pitchdetection_t *p, char_t * pitch_unit);
    9375
    9476#ifdef __cplusplus
  • swig/aubio.i

    rcd77c15 rfe163ad  
    199199
    200200/* pitch detection */
    201 typedef enum {
    202         aubio_pitch_yin,
    203         aubio_pitch_mcomb,
    204         aubio_pitch_schmitt,
    205         aubio_pitch_fcomb,
    206         aubio_pitch_yinfft
    207 } aubio_pitchdetection_type;
    208 
    209 typedef enum {
    210         aubio_pitchm_freq,
    211         aubio_pitchm_midi,
    212         aubio_pitchm_cent,
    213         aubio_pitchm_bin
    214 } aubio_pitchdetection_mode;
    215 
     201aubio_pitchdetection_t *new_aubio_pitchdetection (char *pitch_mode,
     202    uint_t bufsize, uint_t hopsize, uint_t channels, uint_t samplerate);
    216203void aubio_pitchdetection_do (aubio_pitchdetection_t * p, fvec_t * ibuf, fvec_t * obuf);
    217 
    218204void aubio_pitchdetection_set_tolerance(aubio_pitchdetection_t *p, smpl_t thres);
    219 
     205void aubio_pitchdetection_set_unit(aubio_pitchdetection_t *p, char * pitch_unit);
    220206void del_aubio_pitchdetection(aubio_pitchdetection_t * p);
    221 
    222 aubio_pitchdetection_t * new_aubio_pitchdetection(uint_t bufsize,
    223     uint_t hopsize,
    224     uint_t channels,
    225     uint_t samplerate,
    226     aubio_pitchdetection_type type,
    227     aubio_pitchdetection_mode mode);
    228207
    229208
  • tests/src/test-pitchdetection.c

    rcd77c15 rfe163ad  
    11#include <aubio.h>
    22
    3 int main(){
    4         /* allocate some memory */
    5         uint_t win_s      = 1024;                       /* window size */
    6         uint_t hop_s      = win_s/4;                    /* hop size */
    7         uint_t samplerate = 44100;                      /* samplerate */
    8         uint_t channels   = 1;                          /* number of channel */
    9         aubio_pitchdetection_mode mode = aubio_pitchm_freq;
    10         aubio_pitchdetection_type type = aubio_pitch_yinfft;
    11         fvec_t * in       = new_fvec (hop_s, channels); /* input buffer */
    12         fvec_t * out       = new_fvec (1, channels); /* input buffer */
    13         aubio_pitchdetection_t * o  = new_aubio_pitchdetection(
    14           win_s, hop_s, channels, samplerate, type, mode
    15           );
    16         uint_t i = 0;
     3int
     4main ()
     5{
     6  /* allocate some memory */
     7  uint_t win_s = 1024;          /* window size */
     8  uint_t hop_s = win_s / 4;     /* hop size */
     9  uint_t samplerate = 44100;    /* samplerate */
     10  uint_t channels = 1;          /* number of channel */
     11  fvec_t *in = new_fvec (hop_s, channels);      /* input buffer */
     12  fvec_t *out = new_fvec (1, channels); /* input buffer */
     13  aubio_pitchdetection_t *o =
     14      new_aubio_pitchdetection ("default", win_s, hop_s, channels, samplerate);
     15  uint_t i = 0;
    1716
    18         while (i < 100) {
    19           aubio_pitchdetection_do (o,in, out);
    20           i++;
    21         };
     17  while (i < 100) {
     18    aubio_pitchdetection_do (o, in, out);
     19    i++;
     20  };
    2221
    23         del_aubio_pitchdetection(o);
    24         del_fvec(in);
    25         aubio_cleanup();
     22  del_aubio_pitchdetection (o);
     23  del_fvec (in);
     24  aubio_cleanup ();
    2625
    27         return 0;
     26  return 0;
    2827}
Note: See TracChangeset for help on using the changeset viewer.