Changeset fddfa64 for src/pitch/pitch.c


Ignore:
Timestamp:
Nov 3, 2009, 4:14:03 PM (14 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:
bafe71d
Parents:
63f3c70
Message:

src/pitch/: indent

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/pitch/pitch.c

    r63f3c70 rfddfa64  
    3636
    3737/** pitch detection algorithm */
    38 typedef enum {
     38typedef enum
     39{
    3940  aubio_pitcht_yin,     /**< YIN algorithm */
    4041  aubio_pitcht_mcomb,   /**< Multi-comb filter */
     
    4647
    4748/** pitch detection output mode */
    48 typedef enum {
     49typedef enum
     50{
    4951  aubio_pitchm_freq,   /**< Frequency (Hz) */
    5052  aubio_pitchm_midi,   /**< MIDI note (0.,127) */
     
    5557
    5658typedef void (*aubio_pitch_func_t)
    57   (aubio_pitch_t *p, fvec_t * ibuf, fvec_t *obuf);
     59  (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);
    5860typedef smpl_t (*aubio_pitch_conv_t)
    5961  (smpl_t value, uint_t srate, uint_t bufsize);
    6062
    61 void aubio_pitch_slideblock(aubio_pitch_t *p, fvec_t *ibuf);
    62 
    63 void aubio_pitch_do_mcomb   (aubio_pitch_t *p, fvec_t *ibuf, fvec_t *obuf);
    64 void aubio_pitch_do_yin     (aubio_pitch_t *p, fvec_t *ibuf, fvec_t *obuf);
    65 void aubio_pitch_do_schmitt (aubio_pitch_t *p, fvec_t *ibuf, fvec_t *obuf);
    66 void aubio_pitch_do_fcomb   (aubio_pitch_t *p, fvec_t *ibuf, fvec_t *obuf);
    67 void aubio_pitch_do_yinfft  (aubio_pitch_t *p, fvec_t *ibuf, fvec_t *obuf);
     63void aubio_pitch_slideblock (aubio_pitch_t * p, fvec_t * ibuf);
     64
     65void aubio_pitch_do_mcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);
     66void aubio_pitch_do_yin (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);
     67void aubio_pitch_do_schmitt (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);
     68void aubio_pitch_do_fcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);
     69void aubio_pitch_do_yinfft (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);
    6870
    6971/** generic pitch detection structure */
    70 struct _aubio_pitch_t {
     72struct _aubio_pitch_t
     73{
    7174  aubio_pitch_type type; /**< pitch detection mode */
    7275  aubio_pitch_mode mode; /**< pitch detection output mode */
    7376  uint_t srate;                   /**< samplerate */
    7477  uint_t bufsize;                 /**< buffer size */
    75   aubio_pitchmcomb_t * mcomb;     /**< mcomb object */
    76   aubio_pitchfcomb_t * fcomb;     /**< fcomb object */
    77   aubio_pitchschmitt_t * schmitt; /**< schmitt object */
    78   aubio_pitchyinfft_t * yinfft;   /**< yinfft object */
    79   aubio_pitchyin_t * yin;   /**< yinfft object */
    80   aubio_filter_t * filter;        /**< filter */
    81   aubio_pvoc_t * pv;              /**< phase vocoder for mcomb */
    82   cvec_t * fftgrain;              /**< spectral frame for mcomb */
    83   fvec_t * buf;                   /**< temporary buffer for yin */
     78  aubio_pitchmcomb_t *mcomb;      /**< mcomb object */
     79  aubio_pitchfcomb_t *fcomb;      /**< fcomb object */
     80  aubio_pitchschmitt_t *schmitt; /**< schmitt object */
     81  aubio_pitchyinfft_t *yinfft;    /**< yinfft object */
     82  aubio_pitchyin_t *yin;    /**< yinfft object */
     83  aubio_filter_t *filter;         /**< filter */
     84  aubio_pvoc_t *pv;               /**< phase vocoder for mcomb */
     85  cvec_t *fftgrain;               /**< spectral frame for mcomb */
     86  fvec_t *buf;                    /**< temporary buffer for yin */
    8487  aubio_pitch_func_t callback; /**< pointer to current pitch detection method */
    85   aubio_pitch_conv_t freqconv; /**< pointer to current pitch conversion method */ 
     88  aubio_pitch_conv_t freqconv; /**< pointer to current pitch conversion method */
    8689};
    8790
    8891/* convenience wrapper function for frequency unit conversions
    8992 * should probably be rewritten with #defines */
    90 smpl_t freqconvbin(smpl_t f,uint_t srate,uint_t bufsize);
    91 smpl_t freqconvbin(smpl_t f,uint_t srate,uint_t bufsize){
    92   return aubio_freqtobin(f,srate,bufsize);
    93 }
    94 
    95 smpl_t freqconvmidi(smpl_t f,uint_t srate,uint_t bufsize);
    96 smpl_t freqconvmidi(smpl_t f,uint_t srate UNUSED,uint_t bufsize UNUSED){
    97   return aubio_freqtomidi(f);
    98 }
    99 
    100 smpl_t freqconvpass(smpl_t f,uint_t srate,uint_t bufsize);
    101 smpl_t freqconvpass(smpl_t f,uint_t srate UNUSED,uint_t bufsize UNUSED){
     93smpl_t freqconvbin (smpl_t f, uint_t srate, uint_t bufsize);
     94smpl_t
     95freqconvbin (smpl_t f, uint_t srate, uint_t bufsize)
     96{
     97  return aubio_freqtobin (f, srate, bufsize);
     98}
     99
     100smpl_t freqconvmidi (smpl_t f, uint_t srate, uint_t bufsize);
     101smpl_t
     102freqconvmidi (smpl_t f, uint_t srate UNUSED, uint_t bufsize UNUSED)
     103{
     104  return aubio_freqtomidi (f);
     105}
     106
     107smpl_t freqconvpass (smpl_t f, uint_t srate, uint_t bufsize);
     108smpl_t
     109freqconvpass (smpl_t f, uint_t srate UNUSED, uint_t bufsize UNUSED)
     110{
    102111  return f;
    103112}
     
    107116    uint_t bufsize, uint_t hopsize, uint_t channels, uint_t samplerate)
    108117{
    109   aubio_pitch_t *p = AUBIO_NEW(aubio_pitch_t);
     118  aubio_pitch_t *p = AUBIO_NEW (aubio_pitch_t);
    110119  aubio_pitch_type pitch_type;
    111120  if (strcmp (pitch_mode, "mcomb") == 0)
    112       pitch_type = aubio_pitcht_mcomb;
     121    pitch_type = aubio_pitcht_mcomb;
    113122  else if (strcmp (pitch_mode, "yinfft") == 0)
    114       pitch_type = aubio_pitcht_yin;
     123    pitch_type = aubio_pitcht_yin;
    115124  else if (strcmp (pitch_mode, "yin") == 0)
    116       pitch_type = aubio_pitcht_yin;
     125    pitch_type = aubio_pitcht_yin;
    117126  else if (strcmp (pitch_mode, "schmitt") == 0)
    118       pitch_type = aubio_pitcht_schmitt;
     127    pitch_type = aubio_pitcht_schmitt;
    119128  else if (strcmp (pitch_mode, "fcomb") == 0)
    120       pitch_type = aubio_pitcht_fcomb;
     129    pitch_type = aubio_pitcht_fcomb;
    121130  else if (strcmp (pitch_mode, "default") == 0)
    122       pitch_type = aubio_pitcht_default;
     131    pitch_type = aubio_pitcht_default;
    123132  else {
    124       AUBIO_ERR ("unknown pitch detection method %s, using default.\n", pitch_mode);
    125       pitch_type = aubio_pitcht_default;
    126       return NULL;
     133    AUBIO_ERR ("unknown pitch detection method %s, using default.\n",
     134        pitch_mode);
     135    pitch_type = aubio_pitcht_default;
     136    return NULL;
    127137  }
    128138  p->srate = samplerate;
     
    130140  aubio_pitch_set_unit (p, "default");
    131141  p->bufsize = bufsize;
    132   switch(p->type) {
     142  switch (p->type) {
    133143    case aubio_pitcht_yin:
    134       p->buf      = new_fvec(bufsize,channels);
    135       p->yin      = new_aubio_pitchyin(bufsize);
     144      p->buf = new_fvec (bufsize, channels);
     145      p->yin = new_aubio_pitchyin (bufsize);
    136146      p->callback = aubio_pitch_do_yin;
    137147      aubio_pitchyin_set_tolerance (p->yin, 0.15);
    138148      break;
    139149    case aubio_pitcht_mcomb:
    140       p->pv       = new_aubio_pvoc(bufsize, hopsize, channels);
    141       p->fftgrain = new_cvec(bufsize, channels);
    142       p->mcomb    = new_aubio_pitchmcomb(bufsize,hopsize,channels);
    143       p->filter   = new_aubio_filter_c_weighting (samplerate, channels);
     150      p->pv = new_aubio_pvoc (bufsize, hopsize, channels);
     151      p->fftgrain = new_cvec (bufsize, channels);
     152      p->mcomb = new_aubio_pitchmcomb (bufsize, hopsize, channels);
     153      p->filter = new_aubio_filter_c_weighting (samplerate, channels);
    144154      p->callback = aubio_pitch_do_mcomb;
    145155      break;
    146156    case aubio_pitcht_fcomb:
    147       p->buf      = new_fvec(bufsize,channels);
    148       p->fcomb    = new_aubio_pitchfcomb(bufsize,hopsize,channels);
     157      p->buf = new_fvec (bufsize, channels);
     158      p->fcomb = new_aubio_pitchfcomb (bufsize, hopsize, channels);
    149159      p->callback = aubio_pitch_do_fcomb;
    150160      break;
    151161    case aubio_pitcht_schmitt:
    152       p->buf      = new_fvec(bufsize,channels);
    153       p->schmitt  = new_aubio_pitchschmitt(bufsize);
     162      p->buf = new_fvec (bufsize, channels);
     163      p->schmitt = new_aubio_pitchschmitt (bufsize);
    154164      p->callback = aubio_pitch_do_schmitt;
    155165      break;
    156166    case aubio_pitcht_yinfft:
    157       p->buf      = new_fvec(bufsize,channels);
    158       p->yinfft   = new_aubio_pitchyinfft(bufsize);
     167      p->buf = new_fvec (bufsize, channels);
     168      p->yinfft = new_aubio_pitchyinfft (bufsize);
    159169      p->callback = aubio_pitch_do_yinfft;
    160170      aubio_pitchyinfft_set_tolerance (p->yinfft, 0.85);
     
    166176}
    167177
    168 void del_aubio_pitch(aubio_pitch_t * p) {
    169   switch(p->type) {
     178void
     179del_aubio_pitch (aubio_pitch_t * p)
     180{
     181  switch (p->type) {
    170182    case aubio_pitcht_yin:
    171       del_fvec(p->buf);
    172       del_aubio_pitchyin(p->yin);
     183      del_fvec (p->buf);
     184      del_aubio_pitchyin (p->yin);
    173185      break;
    174186    case aubio_pitcht_mcomb:
    175       del_aubio_pvoc(p->pv);
    176       del_cvec(p->fftgrain);
    177       del_aubio_filter(p->filter);
    178       del_aubio_pitchmcomb(p->mcomb);
     187      del_aubio_pvoc (p->pv);
     188      del_cvec (p->fftgrain);
     189      del_aubio_filter (p->filter);
     190      del_aubio_pitchmcomb (p->mcomb);
    179191      break;
    180192    case aubio_pitcht_schmitt:
    181       del_fvec(p->buf);
    182       del_aubio_pitchschmitt(p->schmitt);
     193      del_fvec (p->buf);
     194      del_aubio_pitchschmitt (p->schmitt);
    183195      break;
    184196    case aubio_pitcht_fcomb:
    185       del_fvec(p->buf);
    186       del_aubio_pitchfcomb(p->fcomb);
     197      del_fvec (p->buf);
     198      del_aubio_pitchfcomb (p->fcomb);
    187199      break;
    188200    case aubio_pitcht_yinfft:
    189       del_fvec(p->buf);
    190       del_aubio_pitchyinfft(p->yinfft);
     201      del_fvec (p->buf);
     202      del_aubio_pitchyinfft (p->yinfft);
    191203      break;
    192204    default:
    193205      break;
    194206  }
    195   AUBIO_FREE(p);
    196 }
    197 
    198 void aubio_pitch_slideblock(aubio_pitch_t *p, fvec_t *ibuf){
    199   uint_t i,j = 0, overlap_size = 0;
    200   overlap_size = p->buf->length-ibuf->length;
    201   for (i=0;i<p->buf->channels;i++){
    202     for (j=0;j<overlap_size;j++){
    203       p->buf->data[i][j] = p->buf->data[i][j+ibuf->length];
    204     }
    205   }
    206   for (i=0;i<ibuf->channels;i++){
    207     for (j=0;j<ibuf->length;j++){
    208       p->buf->data[i][j+overlap_size] = ibuf->data[i][j];
    209     }
    210   }
    211 }
    212 
    213 uint_t aubio_pitch_set_unit (aubio_pitch_t *p, char_t * pitch_unit) {
     207  AUBIO_FREE (p);
     208}
     209
     210void
     211aubio_pitch_slideblock (aubio_pitch_t * p, fvec_t * ibuf)
     212{
     213  uint_t i, j = 0, overlap_size = 0;
     214  overlap_size = p->buf->length - ibuf->length;
     215  for (i = 0; i < p->buf->channels; i++) {
     216    for (j = 0; j < overlap_size; j++) {
     217      p->buf->data[i][j] = p->buf->data[i][j + ibuf->length];
     218    }
     219  }
     220  for (i = 0; i < ibuf->channels; i++) {
     221    for (j = 0; j < ibuf->length; j++) {
     222      p->buf->data[i][j + overlap_size] = ibuf->data[i][j];
     223    }
     224  }
     225}
     226
     227uint_t
     228aubio_pitch_set_unit (aubio_pitch_t * p, char_t * pitch_unit)
     229{
    214230  aubio_pitch_mode pitch_mode;
    215231  if (strcmp (pitch_unit, "freq") == 0)
    216       pitch_mode = aubio_pitchm_freq;
     232    pitch_mode = aubio_pitchm_freq;
    217233  else if (strcmp (pitch_unit, "midi") == 0)
    218       pitch_mode = aubio_pitchm_midi;
     234    pitch_mode = aubio_pitchm_midi;
    219235  else if (strcmp (pitch_unit, "cent") == 0)
    220       pitch_mode = aubio_pitchm_cent;
     236    pitch_mode = aubio_pitchm_cent;
    221237  else if (strcmp (pitch_unit, "bin") == 0)
    222       pitch_mode = aubio_pitchm_bin;
     238    pitch_mode = aubio_pitchm_bin;
    223239  else if (strcmp (pitch_unit, "default") == 0)
    224       pitch_mode = aubio_pitchm_default;
     240    pitch_mode = aubio_pitchm_default;
    225241  else {
    226       AUBIO_ERR ("unknown pitch detection unit %s, using default\n", pitch_unit);
    227       pitch_mode = aubio_pitchm_default;
     242    AUBIO_ERR ("unknown pitch detection unit %s, using default\n", pitch_unit);
     243    pitch_mode = aubio_pitchm_default;
    228244  }
    229245  p->mode = pitch_mode;
    230   switch(p->mode) {
     246  switch (p->mode) {
    231247    case aubio_pitchm_freq:
    232248      p->freqconv = freqconvpass;
     
    248264}
    249265
    250 uint_t aubio_pitch_set_tolerance(aubio_pitch_t *p, smpl_t tol) {
    251   switch(p->type) {
     266uint_t
     267aubio_pitch_set_tolerance (aubio_pitch_t * p, smpl_t tol)
     268{
     269  switch (p->type) {
    252270    case aubio_pitcht_yin:
    253271      aubio_pitchyin_set_tolerance (p->yin, tol);
     
    262280}
    263281
    264 void aubio_pitch_do (aubio_pitch_t *p, fvec_t * ibuf, fvec_t *obuf) {
    265   uint_t i;
    266   p->callback(p, ibuf, obuf);
     282void
     283aubio_pitch_do (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)
     284{
     285  uint_t i;
     286  p->callback (p, ibuf, obuf);
    267287  for (i = 0; i < obuf->channels; i++) {
    268     p->freqconv(obuf->data[i][0],p->srate,p->bufsize);
    269   }
    270 }
    271 
    272 void aubio_pitch_do_mcomb(aubio_pitch_t *p, fvec_t *ibuf, fvec_t * obuf) {
    273   uint_t i;
    274   aubio_filter_do(p->filter,ibuf);
    275   aubio_pvoc_do(p->pv,ibuf,p->fftgrain);
    276   aubio_pitchmcomb_do(p->mcomb,p->fftgrain, obuf);
     288    p->freqconv (obuf->data[i][0], p->srate, p->bufsize);
     289  }
     290}
     291
     292void
     293aubio_pitch_do_mcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)
     294{
     295  uint_t i;
     296  aubio_filter_do (p->filter, ibuf);
     297  aubio_pvoc_do (p->pv, ibuf, p->fftgrain);
     298  aubio_pitchmcomb_do (p->mcomb, p->fftgrain, obuf);
    277299  for (i = 0; i < obuf->channels; i++) {
    278300    obuf->data[i][0] = aubio_bintofreq (obuf->data[i][0], p->srate, p->bufsize);
     
    280302}
    281303
    282 void aubio_pitch_do_yin(aubio_pitch_t *p, fvec_t *ibuf, fvec_t * obuf) {
     304void
     305aubio_pitch_do_yin (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)
     306{
    283307  smpl_t pitch = 0.;
    284308  uint_t i;
    285   aubio_pitch_slideblock(p,ibuf);
    286   aubio_pitchyin_do(p->yin,p->buf, obuf);
     309  aubio_pitch_slideblock (p, ibuf);
     310  aubio_pitchyin_do (p->yin, p->buf, obuf);
    287311  for (i = 0; i < obuf->channels; i++) {
    288312    pitch = obuf->data[i][0];
    289     if (pitch>0) {
    290       pitch = p->srate/(pitch+0.);
     313    if (pitch > 0) {
     314      pitch = p->srate / (pitch + 0.);
    291315    } else {
    292316      pitch = 0.;
     
    297321
    298322
    299 void aubio_pitch_do_yinfft(aubio_pitch_t *p, fvec_t *ibuf, fvec_t * obuf){
     323void
     324aubio_pitch_do_yinfft (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)
     325{
    300326  smpl_t pitch = 0.;
    301327  uint_t i;
    302   aubio_pitch_slideblock(p,ibuf);
    303   aubio_pitchyinfft_do(p->yinfft,p->buf,obuf);
     328  aubio_pitch_slideblock (p, ibuf);
     329  aubio_pitchyinfft_do (p->yinfft, p->buf, obuf);
    304330  for (i = 0; i < obuf->channels; i++) {
    305331    pitch = obuf->data[i][0];
    306     if (pitch>0) {
    307       pitch = p->srate/(pitch+0.);
     332    if (pitch > 0) {
     333      pitch = p->srate / (pitch + 0.);
    308334    } else {
    309335      pitch = 0.;
     
    313339}
    314340
    315 void aubio_pitch_do_fcomb(aubio_pitch_t *p, fvec_t *ibuf, fvec_t * out){
    316   uint_t i;
    317   aubio_pitch_slideblock(p,ibuf);
    318   aubio_pitchfcomb_do(p->fcomb,p->buf, out);
     341void
     342aubio_pitch_do_fcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * out)
     343{
     344  uint_t i;
     345  aubio_pitch_slideblock (p, ibuf);
     346  aubio_pitchfcomb_do (p->fcomb, p->buf, out);
    319347  for (i = 0; i < out->channels; i++) {
    320348    out->data[i][0] = aubio_bintofreq (out->data[i][0], p->srate, p->bufsize);
     
    322350}
    323351
    324 void aubio_pitch_do_schmitt(aubio_pitch_t *p, fvec_t *ibuf, fvec_t *out){
     352void
     353aubio_pitch_do_schmitt (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * out)
     354{
    325355  smpl_t period, pitch = 0.;
    326356  uint_t i;
    327   aubio_pitch_slideblock(p,ibuf);
    328   aubio_pitchschmitt_do(p->schmitt,p->buf, out);
     357  aubio_pitch_slideblock (p, ibuf);
     358  aubio_pitchschmitt_do (p->schmitt, p->buf, out);
    329359  for (i = 0; i < out->channels; i++) {
    330360    period = out->data[i][0];
    331     if (period>0) {
    332       pitch = p->srate/period;
     361    if (period > 0) {
     362      pitch = p->srate / period;
    333363    } else {
    334364      pitch = 0.;
Note: See TracChangeset for help on using the changeset viewer.