Changeset 4a95f83


Ignore:
Timestamp:
Mar 16, 2013, 10:44:19 PM (12 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:
3a67894
Parents:
8da0033
Message:

src/pitch/pitchyinfft.c: optimize by avoiding polar coordinates, closes #7

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/pitch/pitchyinfft.c

    r8da0033 r4a95f83  
    3131  fvec_t *win;        /**< temporal weighting window */
    3232  fvec_t *winput;     /**< windowed spectrum */
    33   cvec_t *res;        /**< complex vector to compute square difference function */
    3433  fvec_t *sqrmag;     /**< square difference function */
    3534  fvec_t *weight;     /**< spectral weighting window (psychoacoustic model) */
    36   cvec_t *fftout;     /**< Fourier transform output */
     35  fvec_t *fftout;     /**< Fourier transform output */
     36  fvec_t *res;        /**< complex vector to compute square difference function */
    3737  aubio_fft_t *fft;   /**< fft object to compute square difference function */
    3838  fvec_t *yinfft;     /**< Yin function */
     
    5959  p->winput = new_fvec (bufsize);
    6060  p->fft = new_aubio_fft (bufsize);
    61   p->fftout = new_cvec (bufsize);
     61  p->fftout = new_fvec (bufsize);
     62  p->res = new_fvec (bufsize);
    6263  p->sqrmag = new_fvec (bufsize);
    63   p->res = new_cvec (bufsize);
    6464  p->yinfft = new_fvec (bufsize / 2 + 1);
    6565  p->tol = 0.85;
     
    101101  uint_t halfperiod;
    102102  smpl_t tmp, sum;
    103   cvec_t *res = (cvec_t *) p->res;
     103  fvec_t *res = (fvec_t *) p->res;
    104104  fvec_t *yin = (fvec_t *) p->yinfft;
    105105  l = 0;
     
    109109    p->winput->data[l] = p->win->data[l] * input->data[l];
    110110  }
    111   aubio_fft_do (p->fft, p->winput, p->fftout);
    112   p->sqrmag->data[0] = SQR (p->fftout->norm[0]);
     111  aubio_fft_do_complex (p->fft, p->winput, p->fftout);
     112  uint_t length = p->fftout->length;
     113  p->sqrmag->data[0] = SQR(p->fftout->data[0]);
    113114  p->sqrmag->data[0] *= p->weight->data[0];
    114   for (l = 1; l < p->fftout->length; l++) {
    115     p->sqrmag->data[l] = SQR (p->fftout->norm[l]);
     115  for (l = 1; l < length / 2; l++) {
     116    p->sqrmag->data[l] = SQR(p->fftout->data[l]) + SQR(p->fftout->data[length - l]);
    116117    p->sqrmag->data[l] *= p->weight->data[l];
    117118    p->sqrmag->data[p->sqrmag->length - l] = p->sqrmag->data[l];
    118119  }
    119   for (l = 0; l < p->fftout->length; l++) {
     120  p->sqrmag->data[length / 2] = SQR(p->fftout->data[length / 2]);
     121  p->sqrmag->data[length / 2] *= p->weight->data[length / 2];
     122  for (l = 0; l < length / 2 + 1; l++) {
    120123    sum += p->sqrmag->data[l];
    121124  }
    122125  sum *= 2.;
    123   aubio_fft_do (p->fft, p->sqrmag, res);
     126  aubio_fft_do_complex (p->fft, p->sqrmag, res);
    124127  yin->data[0] = 1.;
    125128  for (tau = 1; tau < yin->length; tau++) {
    126     yin->data[tau] = sum - res->norm[tau] * COS (res->phas[tau]);
     129    yin->data[tau] = sum - res->data[tau];
    127130    tmp += yin->data[tau];
    128131    yin->data[tau] *= tau / tmp;
     
    157160  del_fvec (p->yinfft);
    158161  del_fvec (p->sqrmag);
    159   del_cvec (p->res);
    160   del_cvec (p->fftout);
     162  del_fvec (p->fftout);
     163  del_fvec (p->res);
    161164  del_fvec (p->winput);
    162165  del_fvec (p->weight);
Note: See TracChangeset for help on using the changeset viewer.