ref: c268bf2c950b5e3243fa03f15c2b4f1ef095175a
parent: 67b2dbcccacd2a131de91e9e636456f6063868c7
author: Paul Brossier <piem@piem.org>
date: Tue May 9 12:04:03 EDT 2017
src/pitch/pitch.c: add yinfast
--- a/src/pitch/pitch.c
+++ b/src/pitch/pitch.c
@@ -32,6 +32,7 @@
#include "pitch/pitchfcomb.h"
#include "pitch/pitchschmitt.h"
#include "pitch/pitchyinfft.h"
+#include "pitch/pitchyinfast.h"
#include "pitch/pitchspecacf.h"
#include "pitch/pitch.h"
@@ -45,6 +46,7 @@
aubio_pitcht_schmitt, /**< `schmitt`, Schmitt trigger */
aubio_pitcht_fcomb, /**< `fcomb`, Fast comb filter */
aubio_pitcht_yinfft, /**< `yinfft`, Spectral YIN */
+ aubio_pitcht_yinfast, /**< `yinfast`, YIN fast */
aubio_pitcht_specacf, /**< `specacf`, Spectral autocorrelation */
aubio_pitcht_default
= aubio_pitcht_yinfft, /**< `default` */
@@ -94,6 +96,7 @@
static void aubio_pitch_do_schmitt (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
static void aubio_pitch_do_fcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
static void aubio_pitch_do_yinfft (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
+static void aubio_pitch_do_yinfast (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
static void aubio_pitch_do_specacf (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
/* internal functions for frequency conversion */
@@ -117,6 +120,8 @@
}
if (strcmp (pitch_mode, "mcomb") == 0)
pitch_type = aubio_pitcht_mcomb;
+ else if (strcmp (pitch_mode, "yinfast") == 0)
+ pitch_type = aubio_pitcht_yinfast;
else if (strcmp (pitch_mode, "yinfft") == 0)
pitch_type = aubio_pitcht_yinfft;
else if (strcmp (pitch_mode, "yin") == 0)
@@ -192,6 +197,14 @@
p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchyinfft_get_confidence;
aubio_pitchyinfft_set_tolerance (p->p_object, 0.85);
break;
+ case aubio_pitcht_yinfast:
+ p->buf = new_fvec (bufsize);
+ p->p_object = new_aubio_pitchyinfast (bufsize);
+ if (!p->p_object) goto beach;
+ p->detect_cb = aubio_pitch_do_yinfast;
+ p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchyinfast_get_confidence;
+ aubio_pitchyinfast_set_tolerance (p->p_object, 0.15);
+ break;
case aubio_pitcht_specacf:
p->buf = new_fvec (bufsize);
p->p_object = new_aubio_pitchspecacf (bufsize);
@@ -239,6 +252,10 @@
del_fvec (p->buf);
del_aubio_pitchyinfft (p->p_object);
break;
+ case aubio_pitcht_yinfast:
+ del_fvec (p->buf);
+ del_aubio_pitchyinfast (p->p_object);
+ break;
case aubio_pitcht_specacf:
del_fvec (p->buf);
del_aubio_pitchspecacf (p->p_object);
@@ -329,6 +346,9 @@
case aubio_pitcht_yinfft:
aubio_pitchyinfft_set_tolerance (p->p_object, tol);
break;
+ case aubio_pitcht_yinfast:
+ aubio_pitchyinfast_set_tolerance (p->p_object, tol);
+ break;
default:
break;
}
@@ -346,6 +366,9 @@
case aubio_pitcht_yinfft:
tolerance = aubio_pitchyinfft_get_tolerance (p->p_object);
break;
+ case aubio_pitcht_yinfast:
+ tolerance = aubio_pitchyinfast_get_tolerance (p->p_object);
+ break;
default:
break;
}
@@ -414,6 +437,21 @@
smpl_t pitch = 0.;
aubio_pitch_slideblock (p, ibuf);
aubio_pitchyinfft_do (p->p_object, p->buf, obuf);
+ pitch = obuf->data[0];
+ if (pitch > 0) {
+ pitch = p->samplerate / (pitch + 0.);
+ } else {
+ pitch = 0.;
+ }
+ obuf->data[0] = pitch;
+}
+
+void
+aubio_pitch_do_yinfast (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf)
+{
+ smpl_t pitch = 0.;
+ aubio_pitch_slideblock (p, ibuf);
+ aubio_pitchyinfast_do (p->p_object, p->buf, obuf);
pitch = obuf->data[0];
if (pitch > 0) {
pitch = p->samplerate / (pitch + 0.);