Changeset fe163ad for src


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

Location:
src/pitch
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.