From: Paul Brossier Date: Fri, 5 Oct 2007 15:10:56 +0000 (+0200) Subject: beattracking.{c,h},tempo.{c,h}: add aubio_beattracking_get_confidence X-Git-Tag: bzr2git~514 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e34b0101944dbd29c994deeabc481d7aa0032b9f;p=aubio.git beattracking.{c,h},tempo.{c,h}: add aubio_beattracking_get_confidence --- diff --git a/examples/tests/test-beattracking.c b/examples/tests/test-beattracking.c index 20fc6b0a..2812a3b0 100644 --- a/examples/tests/test-beattracking.c +++ b/examples/tests/test-beattracking.c @@ -12,7 +12,7 @@ int main(){ uint_t i = 0; - smpl_t curtempo; + smpl_t curtempo, curtempoconf; while (i < 10) { aubio_beattracking_do(tempo,in,out); @@ -21,6 +21,11 @@ int main(){ fprintf(stdout,"%f\n",curtempo); return 1; } + curtempoconf = aubio_beattracking_get_confidence(tempo); + if (curtempoconf != 0.) { + fprintf(stdout,"%f\n",curtempo); + return 1; + } i++; }; diff --git a/examples/tests/test-tempo.c b/examples/tests/test-tempo.c index 84e1e32d..53906720 100644 --- a/examples/tests/test-tempo.c +++ b/examples/tests/test-tempo.c @@ -9,13 +9,19 @@ int main(){ aubio_tempo_t * o = new_aubio_tempo(aubio_onset_complex, win_s, win_s/4, channels); uint_t i = 0; - smpl_t curtempo; + smpl_t curtempo, curtempoconf; while (i < 1000) { aubio_tempo(o,in,out); curtempo = aubio_tempo_get_bpm(o); if (curtempo != 0.) { fprintf(stdout,"%f\n",curtempo); + return 1; + } + curtempoconf = aubio_beattracking_get_confidence(o); + if (curtempoconf != 0.) { + fprintf(stdout,"%f\n",curtempo); + return 1; } i++; }; diff --git a/src/beattracking.c b/src/beattracking.c index 6d30ee07..e67a6082 100644 --- a/src/beattracking.c +++ b/src/beattracking.c @@ -460,3 +460,8 @@ smpl_t aubio_beattracking_get_bpm(aubio_beattracking_t * bt) { return 0.; } } + +smpl_t aubio_beattracking_get_confidence(aubio_beattracking_t * bt) { + if (bt->gp) return vec_max(bt->acfout); + else return 0.; +} diff --git a/src/beattracking.h b/src/beattracking.h index 78da1fcd..c6964e9c 100644 --- a/src/beattracking.h +++ b/src/beattracking.h @@ -68,6 +68,15 @@ void aubio_beattracking_do(aubio_beattracking_t * bt, fvec_t * dfframes, fvec_t */ smpl_t aubio_beattracking_get_bpm(aubio_beattracking_t * bt); +/** get current tempo confidence + + \param bt beat tracking object + + Returns the confidence with which the tempo has been observed, 0 if no + consistent value is found. + +*/ +smpl_t aubio_beattracking_get_confidence(aubio_beattracking_t * bt); /** delete beat tracking object \param p beat tracking object diff --git a/src/tempo.c b/src/tempo.c index 328a7e7e..4eb56f26 100644 --- a/src/tempo.c +++ b/src/tempo.c @@ -127,6 +127,10 @@ smpl_t aubio_tempo_get_bpm(aubio_tempo_t *o) { return aubio_beattracking_get_bpm(o->bt); } +smpl_t aubio_tempo_get_confidence(aubio_tempo_t *o) { + return aubio_beattracking_get_confidence(o->bt); +} + void del_aubio_tempo (aubio_tempo_t *o) { del_aubio_onsetdetection(o->od); diff --git a/src/tempo.h b/src/tempo.h index f3faf6e5..ef302189 100644 --- a/src/tempo.h +++ b/src/tempo.h @@ -58,6 +58,16 @@ void aubio_tempo_set_threshold(aubio_tempo_t * o, smpl_t threshold); */ smpl_t aubio_tempo_get_bpm(aubio_tempo_t * bt); +/** get current tempo confidence + + \param bt beat tracking object + + Returns the confidence with which the tempo has been observed, 0 if no + consistent value is found. + +*/ +smpl_t aubio_tempo_get_confidence(aubio_tempo_t * bt); + /** delete tempo detection object */ void del_aubio_tempo(aubio_tempo_t * o); diff --git a/swig/aubio.i b/swig/aubio.i index 7810f619..c4a48fcf 100644 --- a/swig/aubio.i +++ b/swig/aubio.i @@ -257,6 +257,8 @@ void aubio_tss_do(aubio_tss_t *s, cvec_t * input, cvec_t * trans, cvec_t * stead aubio_beattracking_t * new_aubio_beattracking(uint_t winlen, uint_t channels); void aubio_beattracking_do(aubio_beattracking_t * bt, fvec_t * dfframes, fvec_t * out); void del_aubio_beattracking(aubio_beattracking_t * p); +smpl_t aubio_beattracking_get_bpm(aubio_beattracking_t * p); +smpl_t aubio_beattracking_get_confidence(aubio_beattracking_t * p);