ref: 5284e0dd92ebb8d44da359a3c2729d5f65cfad5e
parent: 8c4560e5e6eb281591a04e5d40eb715d35b97f86
author: Paul Brossier <piem@piem.org>
date: Sun Mar 10 15:15:47 EDT 2013
src/pitch: start adding confidence
--- a/src/pitch/pitch.c
+++ b/src/pitch/pitch.c
@@ -61,13 +61,15 @@
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,6 +83,7 @@
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 */
@@ -87,6 +90,7 @@
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 @@
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 @@
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:
@@ -343,4 +352,14 @@
pitch = 0.;
}
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.;
}
--- a/src/pitch/pitchyin.c
+++ b/src/pitch/pitchyin.c
@@ -36,6 +36,7 @@
{
fvec_t *yin;
smpl_t tol;
+ smpl_t confidence;
};
/** compute difference function
@@ -156,6 +157,12 @@
out->data[0] = fvec_quadint (yin, fvec_min_elem (yin));
beach:
return;
+}
+
+smpl_t
+aubio_pitchyin_get_confidence (aubio_pitchyin_t * o) {
+ o->confidence = 1. - fvec_min (o->yin);
+ return o->confidence;
}
uint_t
--- a/src/pitch/pitchyin.h
+++ b/src/pitch/pitchyin.h
@@ -84,6 +84,14 @@
*/
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
--- a/src/pitch/pitchyinfft.c
+++ b/src/pitch/pitchyinfft.c
@@ -37,6 +37,7 @@
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.,
@@ -163,6 +164,12 @@
del_fvec (p->winput);
del_fvec (p->weight);
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
--- a/src/pitch/pitchyinfft.h
+++ b/src/pitch/pitchyinfft.h
@@ -83,6 +83,14 @@
*/
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