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/pitchfcomb.c

    r63f3c70 rfddfa64  
    3030#define MAX_PEAKS 8
    3131
    32 typedef struct {
     32typedef struct
     33{
    3334  smpl_t bin;
    3435  smpl_t db;
    3536} aubio_fpeak_t;
    3637
    37 struct _aubio_pitchfcomb_t {
     38struct _aubio_pitchfcomb_t
     39{
    3840  uint_t fftSize;
    3941  uint_t stepSize;
    4042  uint_t rate;
    41   fvec_t * winput;
    42   fvec_t * win;
    43   cvec_t * fftOut;
    44   fvec_t * fftLastPhase;
    45   aubio_fft_t * fft;
     43  fvec_t *winput;
     44  fvec_t *win;
     45  cvec_t *fftOut;
     46  fvec_t *fftLastPhase;
     47  aubio_fft_t *fft;
    4648};
    4749
    48 aubio_pitchfcomb_t * new_aubio_pitchfcomb (uint_t bufsize, uint_t hopsize, uint_t channels)
     50aubio_pitchfcomb_t *
     51new_aubio_pitchfcomb (uint_t bufsize, uint_t hopsize, uint_t channels)
    4952{
    50   aubio_pitchfcomb_t * p = AUBIO_NEW(aubio_pitchfcomb_t);
    51   p->fftSize      = bufsize;
    52   p->stepSize     = hopsize;
    53   p->winput       = new_fvec(bufsize,1);
    54   p->fftOut       = new_cvec(bufsize,1);
    55   p->fftLastPhase = new_fvec(bufsize, channels);
    56   p->fft = new_aubio_fft(bufsize, 1);
    57   p->win = new_aubio_window("hanning", bufsize);
     53  aubio_pitchfcomb_t *p = AUBIO_NEW (aubio_pitchfcomb_t);
     54  p->fftSize = bufsize;
     55  p->stepSize = hopsize;
     56  p->winput = new_fvec (bufsize, 1);
     57  p->fftOut = new_cvec (bufsize, 1);
     58  p->fftLastPhase = new_fvec (bufsize, channels);
     59  p->fft = new_aubio_fft (bufsize, 1);
     60  p->win = new_aubio_window ("hanning", bufsize);
    5861  return p;
    5962}
    6063
    6164/* input must be stepsize long */
    62 void aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, fvec_t * input, fvec_t * output)
     65void
     66aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, fvec_t * input, fvec_t * output)
    6367{
    6468  uint_t i, k, l, maxharm = 0;
    65   smpl_t phaseDifference = TWO_PI*(smpl_t)p->stepSize/(smpl_t)p->fftSize;
     69  smpl_t phaseDifference = TWO_PI * (smpl_t) p->stepSize / (smpl_t) p->fftSize;
    6670  aubio_fpeak_t peaks[MAX_PEAKS];
    6771
    6872  for (i = 0; i < input->channels; i++) {
    6973
    70   for (k=0; k<MAX_PEAKS; k++) {
    71     peaks[k].db = -200.;
    72     peaks[k].bin = 0.;
    73   }
     74    for (k = 0; k < MAX_PEAKS; k++) {
     75      peaks[k].db = -200.;
     76      peaks[k].bin = 0.;
     77    }
    7478
    75   for (k=0; k < input->length; k++){
    76     p->winput->data[0][k] = p->win->data[0][k] * input->data[i][k];
    77   }
    78   aubio_fft_do(p->fft,p->winput,p->fftOut);
     79    for (k = 0; k < input->length; k++) {
     80      p->winput->data[0][k] = p->win->data[0][k] * input->data[i][k];
     81    }
     82    aubio_fft_do (p->fft, p->winput, p->fftOut);
    7983
    80   for (k=0; k<=p->fftSize/2; k++) {
    81     smpl_t
    82       magnitude = 20.*LOG10(2.*p->fftOut->norm[0][k]/(smpl_t)p->fftSize),
    83       phase     = p->fftOut->phas[0][k],
    84       tmp, bin;
     84    for (k = 0; k <= p->fftSize / 2; k++) {
     85      smpl_t
     86          magnitude =
     87          20. * LOG10 (2. * p->fftOut->norm[0][k] / (smpl_t) p->fftSize),
     88          phase = p->fftOut->phas[0][k], tmp, bin;
    8589
    86     /* compute phase difference */
    87     tmp = phase - p->fftLastPhase->data[i][k];
    88     p->fftLastPhase->data[i][k] = phase;
     90      /* compute phase difference */
     91      tmp = phase - p->fftLastPhase->data[i][k];
     92      p->fftLastPhase->data[i][k] = phase;
    8993
    90     /* subtract expected phase difference */
    91     tmp -= (smpl_t)k*phaseDifference;
     94      /* subtract expected phase difference */
     95      tmp -= (smpl_t) k *phaseDifference;
    9296
    93     /* map delta phase into +/- Pi interval */
    94     tmp = aubio_unwrap2pi(tmp);
     97      /* map delta phase into +/- Pi interval */
     98      tmp = aubio_unwrap2pi (tmp);
    9599
    96     /* get deviation from bin frequency from the +/- Pi interval */
    97     tmp = p->fftSize/(smpl_t)p->stepSize*tmp/(TWO_PI);
     100      /* get deviation from bin frequency from the +/- Pi interval */
     101      tmp = p->fftSize / (smpl_t) p->stepSize * tmp / (TWO_PI);
    98102
    99     /* compute the k-th partials' true bin */
    100     bin = (smpl_t)k + tmp;
     103      /* compute the k-th partials' true bin */
     104      bin = (smpl_t) k + tmp;
    101105
    102     if (bin > 0.0 && magnitude > peaks[0].db) { // && magnitude < 0) {
    103       memmove(peaks+1, peaks, sizeof(aubio_fpeak_t)*(MAX_PEAKS-1));
    104       peaks[0].bin = bin;
    105       peaks[0].db = magnitude;
     106      if (bin > 0.0 && magnitude > peaks[0].db) {       // && magnitude < 0) {
     107        memmove (peaks + 1, peaks, sizeof (aubio_fpeak_t) * (MAX_PEAKS - 1));
     108        peaks[0].bin = bin;
     109        peaks[0].db = magnitude;
     110      }
    106111    }
    107   }
    108112
    109   k = 0;
    110   for (l=1; l<MAX_PEAKS && peaks[l].bin > 0.0; l++) {
    111     sint_t harmonic;
    112     for (harmonic=5; harmonic>1; harmonic--) {
    113       if (peaks[0].bin / peaks[l].bin < harmonic+.02 &&
    114           peaks[0].bin / peaks[l].bin > harmonic-.02) {
    115         if (harmonic > (sint_t)maxharm &&
    116             peaks[0].db < peaks[l].db/2) {
    117           maxharm = harmonic;
    118           k = l;
     113    k = 0;
     114    for (l = 1; l < MAX_PEAKS && peaks[l].bin > 0.0; l++) {
     115      sint_t harmonic;
     116      for (harmonic = 5; harmonic > 1; harmonic--) {
     117        if (peaks[0].bin / peaks[l].bin < harmonic + .02 &&
     118            peaks[0].bin / peaks[l].bin > harmonic - .02) {
     119          if (harmonic > (sint_t) maxharm && peaks[0].db < peaks[l].db / 2) {
     120            maxharm = harmonic;
     121            k = l;
     122          }
    119123        }
    120124      }
    121125    }
    122   }
    123   output->data[i][0] = peaks[k].bin;
    124   /* quick hack to clean output a bit */
    125   if (peaks[k].bin > 5000.) output->data[i][0] = 0.;
     126    output->data[i][0] = peaks[k].bin;
     127    /* quick hack to clean output a bit */
     128    if (peaks[k].bin > 5000.)
     129      output->data[i][0] = 0.;
    126130  }
    127131}
    128132
    129 void del_aubio_pitchfcomb (aubio_pitchfcomb_t * p)
     133void
     134del_aubio_pitchfcomb (aubio_pitchfcomb_t * p)
    130135{
    131   del_cvec(p->fftOut);
    132   del_fvec(p->fftLastPhase);
    133   del_fvec(p->win);
    134   del_fvec(p->winput);
    135   del_aubio_fft(p->fft);
    136   AUBIO_FREE(p);
     136  del_cvec (p->fftOut);
     137  del_fvec (p->fftLastPhase);
     138  del_fvec (p->win);
     139  del_fvec (p->winput);
     140  del_aubio_fft (p->fft);
     141  AUBIO_FREE (p);
    137142}
    138 
Note: See TracChangeset for help on using the changeset viewer.