void aubio_pitchmcomb_do (aubio_pitchmcomb_t * p, cvec_t * fftgrain, fvec_t * output) { uint_t j; smpl_t instfreq; fvec_t *newmag = (fvec_t *) p->newmag; //smpl_t hfc; //fe=instfreq(theta1,theta,ops); //theta1=theta; /* copy incoming grain to newmag */ for (j = 0; j < newmag->length; j++) newmag->data[j] = fftgrain->norm[j]; /* detect only if local energy > 10. */ //if (aubio_level_lin (newmag) * newmag->length > 10.) { //hfc = fvec_local_hfc(newmag); //not used aubio_pitchmcomb_spectral_pp (p, newmag); aubio_pitchmcomb_combdet (p, newmag); //aubio_pitchmcomb_sort_cand_freq(p->candidates,p->ncand); //return p->candidates[p->goodcandidate]->ebin; j = (uint_t) FLOOR (p->candidates[p->goodcandidate]->ebin + .5); instfreq = aubio_unwrap2pi (fftgrain->phas[j] - p->theta->data[j] - j * p->phasediff); instfreq *= p->phasefreq; /* store phase for next run */ for (j = 0; j < p->theta->length; j++) { p->theta->data[j] = fftgrain->phas[j]; } //return p->candidates[p->goodcandidate]->ebin; output->data[0] = FLOOR (p->candidates[p->goodcandidate]->ebin + .5) + instfreq; /*} else { return -1.; } */ }
void aubio_tss_do(aubio_tss_t *o, cvec_t * input, cvec_t * trans, cvec_t * stead) { uint_t j; uint_t test; uint_t nbins = input->length; smpl_t alpha = o->alpha; smpl_t beta = o->beta; smpl_t parm = o->parm; smpl_t * dev = (smpl_t *)o->dev->data; smpl_t * oft1 = (smpl_t *)o->oft1->data; smpl_t * oft2 = (smpl_t *)o->oft2->data; smpl_t * theta1 = (smpl_t *)o->theta1->data; smpl_t * theta2 = (smpl_t *)o->theta2->data; /* second phase derivative */ for (j=0;j<nbins; j++){ dev[j] = aubio_unwrap2pi(input->phas[j] -2.0*theta1[j]+theta2[j]); theta2[j] = theta1[j]; theta1[j] = input->phas[j]; } for (j=0;j<nbins; j++){ /* transient analysis */ test = (ABS(dev[j]) > parm*oft1[j]); trans->norm[j] = input->norm[j] * test; trans->phas[j] = input->phas[j] * test; } for (j=0;j<nbins; j++){ /* steady state analysis */ test = (ABS(dev[j]) < parm*oft2[j]); stead->norm[j] = input->norm[j] * test; stead->phas[j] = input->phas[j] * test; /*increase sstate probability for sines */ test = (trans->norm[j]==0.); oft1[j] = test; test = (stead->norm[j]==0.); oft2[j] = test; test = (trans->norm[j]>0.); oft1[j] += alpha*test; test = (stead->norm[j]>0.); oft2[j] += alpha*test; test = (oft1[j]>1. && trans->norm[j]>0.); oft1[j] += beta*test; test = (oft2[j]>1. && stead->norm[j]>0.); oft2[j] += beta*test; } }
/* 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.; }