From: Paul Brossier Date: Mon, 11 Mar 2013 00:15:47 +0000 (-0500) Subject: src/pitch: start adding confidence X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=5284e0dd92ebb8d44da359a3c2729d5f65cfad5e;p=aubio.git src/pitch: start adding confidence --- diff --git a/src/pitch/pitch.c b/src/pitch/pitch.c index 63366c03..ba963442 100644 --- a/src/pitch/pitch.c +++ b/src/pitch/pitch.c @@ -61,13 +61,15 @@ typedef void (*aubio_pitch_func_t) typedef smpl_t (*aubio_pitch_conv_t) (smpl_t value, uint_t srate, uint_t bufsize); +typedef smpl_t (*aubio_conf_cb_t) (void * p); + void aubio_pitch_slideblock (aubio_pitch_t * p, fvec_t * ibuf); -void aubio_pitch_do_mcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf); -void aubio_pitch_do_yin (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf); -void aubio_pitch_do_schmitt (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf); -void aubio_pitch_do_fcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf); -void aubio_pitch_do_yinfft (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf); +static void aubio_pitch_do_mcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf); +static void aubio_pitch_do_yin (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf); +static void aubio_pitch_do_schmitt (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf); +static void aubio_pitch_do_fcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf); +static void aubio_pitch_do_yinfft (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf); /** generic pitch detection structure */ struct _aubio_pitch_t @@ -81,12 +83,14 @@ struct _aubio_pitch_t aubio_pitchschmitt_t *schmitt; /**< schmitt object */ aubio_pitchyinfft_t *yinfft; /**< yinfft object */ aubio_pitchyin_t *yin; /**< yinfft object */ + void *pitch; aubio_filter_t *filter; /**< filter */ aubio_pvoc_t *pv; /**< phase vocoder for mcomb */ cvec_t *fftgrain; /**< spectral frame for mcomb */ fvec_t *buf; /**< temporary buffer for yin */ aubio_pitch_func_t callback; /**< pointer to current pitch detection method */ aubio_pitch_conv_t freqconv; /**< pointer to current pitch conversion method */ + aubio_conf_cb_t confidence_callback; /**< pointer to the current confidence callback */ }; /* convenience wrapper function for frequency unit conversions @@ -139,11 +143,14 @@ new_aubio_pitch (char_t * pitch_mode, p->type = pitch_type; aubio_pitch_set_unit (p, "default"); p->bufsize = bufsize; + p->confidence_callback = NULL; switch (p->type) { case aubio_pitcht_yin: p->buf = new_fvec (bufsize); p->yin = new_aubio_pitchyin (bufsize); p->callback = aubio_pitch_do_yin; + p->confidence_callback = (aubio_conf_cb_t)aubio_pitchyin_get_confidence; + p->pitch = (void*)p->yin; aubio_pitchyin_set_tolerance (p->yin, 0.15); break; case aubio_pitcht_mcomb: @@ -167,6 +174,8 @@ new_aubio_pitch (char_t * pitch_mode, p->buf = new_fvec (bufsize); p->yinfft = new_aubio_pitchyinfft (bufsize); p->callback = aubio_pitch_do_yinfft; + p->confidence_callback = (aubio_conf_cb_t)aubio_pitchyinfft_get_confidence; + p->pitch = (void*)p->yin; aubio_pitchyinfft_set_tolerance (p->yinfft, 0.85); break; default: @@ -344,3 +353,13 @@ aubio_pitch_do_schmitt (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * out) } out->data[0] = pitch; } + +/* confidence callbacks */ +smpl_t +aubio_pitch_get_confidence (aubio_pitch_t * p) +{ + if (p->confidence_callback) { + return p->confidence_callback ((void*)(p->pitch)); + } + return 0.; +} diff --git a/src/pitch/pitchyin.c b/src/pitch/pitchyin.c index ec1a40e7..578c8e62 100644 --- a/src/pitch/pitchyin.c +++ b/src/pitch/pitchyin.c @@ -36,6 +36,7 @@ struct _aubio_pitchyin_t { fvec_t *yin; smpl_t tol; + smpl_t confidence; }; /** compute difference function @@ -158,6 +159,12 @@ beach: return; } +smpl_t +aubio_pitchyin_get_confidence (aubio_pitchyin_t * o) { + o->confidence = 1. - fvec_min (o->yin); + return o->confidence; +} + uint_t aubio_pitchyin_set_tolerance (aubio_pitchyin_t * o, smpl_t tol) { diff --git a/src/pitch/pitchyin.h b/src/pitch/pitchyin.h index d7cd384b..c6f2e1f5 100644 --- a/src/pitch/pitchyin.h +++ b/src/pitch/pitchyin.h @@ -84,6 +84,14 @@ uint_t aubio_pitchyin_set_tolerance (aubio_pitchyin_t * o, smpl_t tol); */ smpl_t aubio_pitchyin_get_tolerance (aubio_pitchyin_t * o); +/** get current confidence of YIN algorithm + + \param o YIN pitch detection object + \return confidence parameter + +*/ +smpl_t aubio_pitchyin_get_confidence (aubio_pitchyin_t * o); + #ifdef __cplusplus } #endif diff --git a/src/pitch/pitchyinfft.c b/src/pitch/pitchyinfft.c index e8c2757e..b627ef2c 100644 --- a/src/pitch/pitchyinfft.c +++ b/src/pitch/pitchyinfft.c @@ -37,6 +37,7 @@ struct _aubio_pitchyinfft_t aubio_fft_t *fft; /**< fft object to compute square difference function */ fvec_t *yinfft; /**< Yin function */ smpl_t tol; /**< Yin tolerance */ + smpl_t confidence; /**< confidence */ }; static const smpl_t freqs[] = { 0., 20., 25., 31.5, 40., 50., 63., 80., 100., @@ -165,6 +166,12 @@ del_aubio_pitchyinfft (aubio_pitchyinfft_t * p) AUBIO_FREE (p); } +smpl_t +aubio_pitchyinfft_get_confidence (aubio_pitchyinfft_t * o) { + o->confidence = 1. - fvec_min (o->yinfft); + return o->confidence; +} + uint_t aubio_pitchyinfft_set_tolerance (aubio_pitchyinfft_t * p, smpl_t tol) { diff --git a/src/pitch/pitchyinfft.h b/src/pitch/pitchyinfft.h index 5c4ab1cc..a26319c4 100644 --- a/src/pitch/pitchyinfft.h +++ b/src/pitch/pitchyinfft.h @@ -83,6 +83,14 @@ smpl_t aubio_pitchyinfft_get_tolerance (aubio_pitchyinfft_t * o); */ uint_t aubio_pitchyinfft_set_tolerance (aubio_pitchyinfft_t * o, smpl_t tol); +/** get current confidence of YIN algorithm + + \param o YIN pitch detection object + \return confidence parameter + +*/ +smpl_t aubio_pitchyinfft_get_confidence (aubio_pitchyinfft_t * o); + #ifdef __cplusplus } #endif