From 9c9202fe489f0ec770c152b7b47b08b152473ed4 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Tue, 9 Apr 2013 18:47:05 -0500 Subject: [PATCH] src/pitch/pitchyinfft.c: adapt filter and shortest period to samplerate --- src/pitch/pitch.c | 2 +- src/pitch/pitchyinfft.c | 9 ++++++--- src/pitch/pitchyinfft.h | 2 +- tests/src/pitch/test-pitchyinfft.c | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/pitch/pitch.c b/src/pitch/pitch.c index e29d7a91..6d488012 100644 --- a/src/pitch/pitch.c +++ b/src/pitch/pitch.c @@ -158,7 +158,7 @@ new_aubio_pitch (char_t * pitch_mode, 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); diff --git a/src/pitch/pitchyinfft.c b/src/pitch/pitchyinfft.c index afae9988..518fbb95 100644 --- a/src/pitch/pitchyinfft.c +++ b/src/pitch/pitchyinfft.c @@ -37,6 +37,7 @@ struct _aubio_pitchyinfft_t 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 @@ static const smpl_t weight[] = { -75.8, -70.1, -60.8, -52.1, -44.2, -37.5, }; 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 @@ new_aubio_pitchyinfft (uint_t bufsize) 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 @@ new_aubio_pitchyinfft (uint_t bufsize) 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 @@ aubio_pitchyinfft_do (aubio_pitchyinfft_t * p, fvec_t * input, fvec_t * output) // 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 */ diff --git a/src/pitch/pitchyinfft.h b/src/pitch/pitchyinfft.h index c63bbe42..07cf2149 100644 --- a/src/pitch/pitchyinfft.h +++ b/src/pitch/pitchyinfft.h @@ -58,7 +58,7 @@ void aubio_pitchyinfft_do (aubio_pitchyinfft_t * o, fvec_t * samples_in, fvec_t \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() diff --git a/tests/src/pitch/test-pitchyinfft.c b/tests/src/pitch/test-pitchyinfft.c index aeccc5b0..158aea71 100644 --- a/tests/src/pitch/test-pitchyinfft.c +++ b/tests/src/pitch/test-pitchyinfft.c @@ -13,7 +13,7 @@ int main () 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-- ) { -- 2.26.2