void aubio_pitchyinfft_do (aubio_pitchyinfft_t * p, fvec_t * input, fvec_t * output) { uint_t tau, l; uint_t halfperiod; smpl_t tmp, sum; cvec_t *res = (cvec_t *) p->res; fvec_t *yin = (fvec_t *) p->yinfft; l = 0; tmp = 0.; sum = 0.; for (l = 0; l < input->length; l++) { p->winput->data[l] = p->win->data[l] * input->data[l]; } aubio_fft_do (p->fft, p->winput, p->fftout); for (l = 0; l < p->fftout->length; l++) { p->sqrmag->data[l] = SQR (p->fftout->norm[l]); p->sqrmag->data[l] *= p->weight->data[l]; } for (l = 1; l < p->fftout->length; l++) { p->sqrmag->data[(p->fftout->length - 1) * 2 - l] = SQR (p->fftout->norm[l]); p->sqrmag->data[(p->fftout->length - 1) * 2 - l] *= p->weight->data[l]; } for (l = 0; l < p->sqrmag->length / 2 + 1; l++) { sum += p->sqrmag->data[l]; } sum *= 2.; aubio_fft_do (p->fft, p->sqrmag, res); yin->data[0] = 1.; for (tau = 1; tau < yin->length; tau++) { yin->data[tau] = sum - res->norm[tau] * COS (res->phas[tau]); tmp += yin->data[tau]; yin->data[tau] *= tau / tmp; } tau = fvec_min_elem (yin); if (yin->data[tau] < p->tol) { /* no interpolation */ //return tau; /* 3 point quadratic interpolation */ //return fvec_quadint_min(yin,tau,1); /* additional check for (unlikely) octave doubling in higher frequencies */ if (tau > 35) { output->data[0] = fvec_quadint (yin, tau); } else { /* should compare the minimum value of each interpolated peaks */ halfperiod = FLOOR (tau / 2 + .5); if (yin->data[halfperiod] < p->tol) output->data[0] = fvec_quadint (yin, halfperiod); else output->data[0] = fvec_quadint (yin, tau); } } else { output->data[0] = 0.; } }
static PyObject * Py_fft_do(Py_fft * self, PyObject * args) { PyObject *input; cvec_t c_out; if (!PyArg_ParseTuple (args, "O", &input)) { return NULL; } if (!PyAubio_ArrayToCFvec(input, &(self->vecin))) { return NULL; } if (self->vecin.length != self->win_s) { PyErr_Format(PyExc_ValueError, "input array has length %d, but fft expects length %d", self->vecin.length, self->win_s); return NULL; } Py_INCREF(self->doout); if (!PyAubio_PyCvecToCCvec(self->doout, &c_out)) { return NULL; } // compute the function aubio_fft_do (self->o, &(self->vecin), &c_out); return self->doout; }
void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t * datanew, cvec_t *fftgrain) { /* slide */ aubio_pvoc_swapbuffers(pv->data->data,pv->dataold->data, datanew->data,pv->win_s,pv->hop_s); /* windowing */ fvec_weight(pv->data, pv->w); /* shift */ fvec_shift(pv->data); /* calculate fft */ aubio_fft_do (pv->fft,pv->data,fftgrain); }
int main (void) { int return_code = 0; uint_t i, n_iters = 100; // number of iterations uint_t win_s = 500; // window size fvec_t * in = new_fvec (win_s); // input buffer cvec_t * fftgrain = new_cvec (win_s); // fft norm and phase fvec_t * out = new_fvec (win_s); // output buffer // create fft object aubio_fft_t * fft = new_aubio_fft(win_s); if (!fft) { return_code = 1; goto beach; } // fill input with some data in->data[0] = 1; in->data[1] = 2; in->data[2] = 3; in->data[3] = 4; in->data[4] = 5; in->data[5] = 6; in->data[6] = 5; in->data[7] = 6; //fvec_print(in); for (i = 0; i < n_iters; i++) { // execute stft aubio_fft_do (fft,in,fftgrain); cvec_print(fftgrain); // execute inverse fourier transform aubio_fft_rdo(fft,fftgrain,out); } // cleam up //fvec_print(out); del_aubio_fft(fft); beach: del_fvec(in); del_cvec(fftgrain); del_fvec(out); aubio_cleanup(); return return_code; }
/* input must be stepsize long */ void aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, const fvec_t * input, fvec_t * output) { uint_t k, l, maxharm = 0; smpl_t phaseDifference = TWO_PI * (smpl_t) p->stepSize / (smpl_t) p->fftSize; aubio_fpeak_t peaks[MAX_PEAKS]; for (k = 0; k < MAX_PEAKS; k++) { peaks[k].db = -200.; peaks[k].bin = 0.; } for (k = 0; k < input->length; k++) { p->winput->data[k] = p->win->data[k] * input->data[k]; } aubio_fft_do (p->fft, p->winput, p->fftOut); for (k = 0; k <= p->fftSize / 2; k++) { smpl_t magnitude = 20. * LOG10 (2. * p->fftOut->norm[k] / (smpl_t) p->fftSize), phase = p->fftOut->phas[k], tmp, bin; /* compute phase difference */ tmp = phase - p->fftLastPhase->data[k]; p->fftLastPhase->data[k] = phase; /* subtract expected phase difference */ tmp -= (smpl_t) k *phaseDifference; /* map delta phase into +/- Pi interval */ tmp = aubio_unwrap2pi (tmp); /* get deviation from bin frequency from the +/- Pi interval */ tmp = p->fftSize / (smpl_t) p->stepSize * tmp / (TWO_PI); /* compute the k-th partials' true bin */ bin = (smpl_t) k + tmp; if (bin > 0.0 && magnitude > peaks[0].db) { // && magnitude < 0) { memmove (peaks + 1, peaks, sizeof (aubio_fpeak_t) * (MAX_PEAKS - 1)); peaks[0].bin = bin; peaks[0].db = magnitude; } } k = 0; for (l = 1; l < MAX_PEAKS && peaks[l].bin > 0.0; l++) { sint_t harmonic; for (harmonic = 5; harmonic > 1; harmonic--) { if (peaks[0].bin / peaks[l].bin < harmonic + .02 && peaks[0].bin / peaks[l].bin > harmonic - .02) { if (harmonic > (sint_t) maxharm && peaks[0].db < peaks[l].db / 2) { maxharm = harmonic; k = l; } } } } output->data[0] = peaks[k].bin; /* quick hack to clean output a bit */ if (peaks[k].bin > 5000.) output->data[0] = 0.; }