Changeset a5f4b7d


Ignore:
Timestamp:
Mar 18, 2013, 9:18:30 AM (7 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
Children:
bb42f65
Parents:
53439af
Message:

src/pitch/pitchyinfft.c: simplify, add some comment, update copyright

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/pitch/pitchyinfft.c

    r53439af ra5f4b7d  
    11/*
    2   Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
     2  Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org>
    33
    44  This file is part of aubio.
     
    3434  fvec_t *weight;     /**< spectral weighting window (psychoacoustic model) */
    3535  fvec_t *fftout;     /**< Fourier transform output */
    36   fvec_t *res;        /**< complex vector to compute square difference function */
    3736  aubio_fft_t *fft;   /**< fft object to compute square difference function */
    3837  fvec_t *yinfft;     /**< Yin function */
     
    6059  p->fft = new_aubio_fft (bufsize);
    6160  p->fftout = new_fvec (bufsize);
    62   p->res = new_fvec (bufsize);
    6361  p->sqrmag = new_fvec (bufsize);
    6462  p->yinfft = new_fvec (bufsize / 2 + 1);
     
    9997{
    10098  uint_t tau, l;
     99  uint_t length = p->fftout->length;
    101100  uint_t halfperiod;
    102   smpl_t tmp, sum;
    103   fvec_t *res = (fvec_t *) p->res;
    104   fvec_t *yin = (fvec_t *) p->yinfft;
    105   l = 0;
    106   tmp = 0.;
    107   sum = 0.;
     101  fvec_t *fftout = p->fftout;
     102  fvec_t *yin = p->yinfft;
     103  smpl_t tmp = 0., sum = 0.;
     104  // window the input
    108105  for (l = 0; l < input->length; l++) {
    109106    p->winput->data[l] = p->win->data[l] * input->data[l];
    110107  }
    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]);
     108  // get the real / imag parts of its fft
     109  aubio_fft_do_complex (p->fft, p->winput, fftout);
     110  // get the squared magnitude spectrum, applying some weight
     111  p->sqrmag->data[0] = SQR(fftout->data[0]);
    114112  p->sqrmag->data[0] *= p->weight->data[0];
    115113  for (l = 1; l < length / 2; l++) {
    116     p->sqrmag->data[l] = SQR(p->fftout->data[l]) + SQR(p->fftout->data[length - l]);
     114    p->sqrmag->data[l] = SQR(fftout->data[l]) + SQR(fftout->data[length - l]);
    117115    p->sqrmag->data[l] *= p->weight->data[l];
    118     p->sqrmag->data[p->sqrmag->length - l] = p->sqrmag->data[l];
     116    p->sqrmag->data[length - l] = p->sqrmag->data[l];
    119117  }
    120   p->sqrmag->data[length / 2] = SQR(p->fftout->data[length / 2]);
     118  p->sqrmag->data[length / 2] = SQR(fftout->data[length / 2]);
    121119  p->sqrmag->data[length / 2] *= p->weight->data[length / 2];
     120  // get sum of weighted squared mags
    122121  for (l = 0; l < length / 2 + 1; l++) {
    123122    sum += p->sqrmag->data[l];
    124123  }
    125124  sum *= 2.;
    126   aubio_fft_do_complex (p->fft, p->sqrmag, res);
     125  // get the real / imag parts of the fft of the squared magnitude
     126  aubio_fft_do_complex (p->fft, p->sqrmag, fftout);
    127127  yin->data[0] = 1.;
    128128  for (tau = 1; tau < yin->length; tau++) {
    129     yin->data[tau] = sum - res->data[tau];
     129    // compute the square differences
     130    yin->data[tau] = sum - fftout->data[tau];
     131    // and the cumulative mean normalized difference function
    130132    tmp += yin->data[tau];
    131133    yin->data[tau] *= tau / tmp;
    132134  }
     135  // find best candidates
    133136  tau = fvec_min_elem (yin);
    134137  if (yin->data[tau] < p->tol) {
    135     /* no interpolation */
    136     //return tau;
    137     /* 3 point quadratic interpolation */
     138    // no interpolation, directly return the period as an integer
     139    //output->data[0] = tau;
     140    //return;
     141
     142    // 3 point quadratic interpolation
    138143    //return fvec_quadint_min(yin,tau,1);
    139144    /* additional check for (unlikely) octave doubling in higher frequencies */
     
    161166  del_fvec (p->sqrmag);
    162167  del_fvec (p->fftout);
    163   del_fvec (p->res);
    164168  del_fvec (p->winput);
    165169  del_fvec (p->weight);
Note: See TracChangeset for help on using the changeset viewer.