Logo Search packages:      
Sourcecode: aubio version File versions  Download package

smpl_t aubio_pitchyinfft_detect ( aubio_pitchyinfft_t p,
fvec_t input,
smpl_t  tol 
)

execute pitch detection on an input buffer

Parameters:
p pitch detection object as returned by new_aubio_pitchyinfft
input input signal window (length as specified at creation time)
tol tolerance parameter for minima selection [default 0.85]

Definition at line 90 of file pitchyinfft.c.

References _fvec_t::data, _aubio_pitchyinfft_t::fft, _aubio_pitchyinfft_t::fftout, _cvec_t::length, _fvec_t::length, _cvec_t::norm, _cvec_t::phas, _aubio_pitchyinfft_t::res, _aubio_pitchyinfft_t::sqrmag, _aubio_pitchyinfft_t::weight, _aubio_pitchyinfft_t::win, _aubio_pitchyinfft_t::winput, and _aubio_pitchyinfft_t::yinfft.

                                                                                     {
  uint_t tau, l = 0;
  uint_t halfperiod;
  smpl_t tmp = 0, sum = 0;
  cvec_t * res = (cvec_t *)p->res;
  fvec_t * yin = (fvec_t *)p->yinfft;
  for (l=0; l < input->length; l++){
        p->winput->data[0][l] = p->win->data[0][l] * input->data[0][l];
  }
  aubio_mfft_do(p->fft,p->winput,p->fftout);
  for (l=0; l < p->fftout->length; l++){
        p->sqrmag->data[0][l] = SQR(p->fftout->norm[0][l]);
        p->sqrmag->data[0][l] *= p->weight->data[0][l]; 
  }
  for (l=1; l < p->fftout->length; l++){
        p->sqrmag->data[0][(p->fftout->length-1)*2-l] = 
         SQR(p->fftout->norm[0][l]);
        p->sqrmag->data[0][(p->fftout->length-1)*2-l] *=
             p->weight->data[0][l];
  }
  for (l=0; l < p->sqrmag->length/2+1; l++) {
        sum += p->sqrmag->data[0][l];
  }
  sum *= 2.;
  aubio_mfft_do(p->fft,p->sqrmag,res);
  yin->data[0][0] = 1.; 
  for (tau=1; tau < yin->length; tau++) {
        yin->data[0][tau] = sum -
              res->norm[0][tau]*COS(res->phas[0][tau]); 
        tmp += yin->data[0][tau];
        yin->data[0][tau] *= tau/tmp;
  }
  tau = vec_min_elem(yin); 
  if (yin->data[0][tau] < tol) {
        /* no interpolation */
        //return tau;
        /* 3 point quadratic interpolation */
        //return vec_quadint_min(yin,tau,1);
        /* additional check for (unlikely) octave doubling in higher frequencies */
        if (tau>35) {
              return vec_quadint_min(yin,tau,1);
        } else {
              /* should compare the minimum value of each interpolated peaks */
              halfperiod = FLOOR(tau/2+.5);
              if (yin->data[0][halfperiod] < tol)
                    return vec_quadint_min(yin,halfperiod,1);
              else
                    return vec_quadint_min(yin,tau,1);
        }
  } else
        return 0;
}


Generated by  Doxygen 1.6.0   Back to index