ref: 9c9202fe489f0ec770c152b7b47b08b152473ed4
parent: 483b883ece7193ea0fb0406408fa323539d288a4
author: Paul Brossier <piem@piem.org>
date: Tue Apr 9 14:47:05 EDT 2013
src/pitch/pitchyinfft.c: adapt filter and shortest period to samplerate
--- a/src/pitch/pitch.c
+++ b/src/pitch/pitch.c
@@ -158,7 +158,7 @@
break;
case aubio_pitcht_yinfft:
p->buf = new_fvec (bufsize);
- p->p_object = new_aubio_pitchyinfft (bufsize);
+ p->p_object = new_aubio_pitchyinfft (samplerate, bufsize);
p->detect_cb = aubio_pitch_do_yinfft;
p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchyinfft_get_confidence;
aubio_pitchyinfft_set_tolerance (p->p_object, 0.85);
--- a/src/pitch/pitchyinfft.c
+++ b/src/pitch/pitchyinfft.c
@@ -37,6 +37,7 @@
fvec_t *yinfft; /**< Yin function */
smpl_t tol; /**< Yin tolerance */
smpl_t confidence; /**< confidence */
+ uint_t short_period; /** shortest period under which to check for octave error */
};
static const smpl_t freqs[] = { 0., 20., 25., 31.5, 40., 50., 63., 80., 100.,
@@ -52,7 +53,7 @@
};
aubio_pitchyinfft_t *
-new_aubio_pitchyinfft (uint_t bufsize)
+new_aubio_pitchyinfft (uint_t samplerate, uint_t bufsize)
{
aubio_pitchyinfft_t *p = AUBIO_NEW (aubio_pitchyinfft_t);
p->winput = new_fvec (bufsize);
@@ -66,7 +67,7 @@
uint_t i = 0, j = 1;
smpl_t freq = 0, a0 = 0, a1 = 0, f0 = 0, f1 = 0;
for (i = 0; i < p->weight->length; i++) {
- freq = (smpl_t) i / (smpl_t) bufsize *(smpl_t) 44100.;
+ freq = (smpl_t) i / (smpl_t) bufsize *(smpl_t) samplerate;
while (freq > freqs[j]) {
j += 1;
}
@@ -89,6 +90,8 @@
p->weight->data[i] = DB2LIN (p->weight->data[i]);
//p->weight->data[i] = SQRT(DB2LIN(p->weight->data[i]));
}
+ // check for octave errors above 1300 Hz
+ p->short_period = (uint_t)ROUND(samplerate / 1300.);
return p;
}
@@ -142,7 +145,7 @@
// 3 point quadratic interpolation
//return fvec_quadratic_peak_pos (yin,tau,1);
/* additional check for (unlikely) octave doubling in higher frequencies */
- if (tau > 35) {
+ if (tau > p->short_period) {
output->data[0] = fvec_quadratic_peak_pos (yin, tau);
} else {
/* should compare the minimum value of each interpolated peaks */
--- a/src/pitch/pitchyinfft.h
+++ b/src/pitch/pitchyinfft.h
@@ -58,7 +58,7 @@
\param buf_size size of the input buffer to analyse
*/
-aubio_pitchyinfft_t *new_aubio_pitchyinfft (uint_t buf_size);
+aubio_pitchyinfft_t *new_aubio_pitchyinfft (uint_t samplerate, uint_t buf_size);
/** deletion of the pitch detection object
\param o pitch detection object as returned by new_aubio_pitchyinfft()
--- a/tests/src/pitch/test-pitchyinfft.c
+++ b/tests/src/pitch/test-pitchyinfft.c
@@ -13,7 +13,7 @@
fvec_t * in = new_fvec (win_s); // input buffer
fvec_t * out = new_fvec (1); // output candidates
// create pitch object
- aubio_pitchyinfft_t *p = new_aubio_pitchyinfft(win_s);
+ aubio_pitchyinfft_t *p = new_aubio_pitchyinfft(44100, win_s);
aubio_pitchyinfft_set_tolerance (p, 0.2);
while ( n-- ) {