Index: src/aubio.h
===================================================================
--- src/aubio.h	(revision 8f343e64c8858d9f83adcc7eb52cdd9173451a11)
+++ src/aubio.h	(revision 107037870a4ec56eeb2fdab92e153b96fd2ab084)
@@ -215,4 +215,5 @@
 #include "pitch/pitchyin.h"
 #include "pitch/pitchyinfft.h"
+#include "pitch/pitchyinfast.h"
 #include "pitch/pitchschmitt.h"
 #include "pitch/pitchfcomb.h"
Index: src/pitch/pitch.c
===================================================================
--- src/pitch/pitch.c	(revision 8f343e64c8858d9f83adcc7eb52cdd9173451a11)
+++ src/pitch/pitch.c	(revision 107037870a4ec56eeb2fdab92e153b96fd2ab084)
@@ -33,4 +33,5 @@
 #include "pitch/pitchschmitt.h"
 #include "pitch/pitchyinfft.h"
+#include "pitch/pitchyinfast.h"
 #include "pitch/pitchspecacf.h"
 #include "pitch/pitch.h"
@@ -46,4 +47,5 @@
   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
@@ -95,4 +97,5 @@
 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);
 
@@ -118,4 +121,6 @@
   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;
@@ -193,4 +198,12 @@
       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);
@@ -239,4 +252,8 @@
       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:
@@ -330,4 +347,7 @@
       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,4 +366,7 @@
     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:
@@ -415,4 +438,19 @@
   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) {
Index: src/pitch/pitch.h
===================================================================
--- src/pitch/pitch.h	(revision 8f343e64c8858d9f83adcc7eb52cdd9173451a11)
+++ src/pitch/pitch.h	(revision 107037870a4ec56eeb2fdab92e153b96fd2ab084)
@@ -81,4 +81,9 @@
 
   see http://recherche.ircam.fr/equipes/pcm/pub/people/cheveign.html
+
+  \b \p yinfast : Yinfast algorithm
+
+  This algorithm is equivalent to the YIN algorithm, but computed in the
+  spectral domain for efficiency. See also `python/demos/demo_yin_compare.py`.
 
   \b \p yinfft : Yinfft algorithm
Index: src/pitch/pitchyinfast.c
===================================================================
--- src/pitch/pitchyinfast.c	(revision 107037870a4ec56eeb2fdab92e153b96fd2ab084)
+++ src/pitch/pitchyinfast.c	(revision 107037870a4ec56eeb2fdab92e153b96fd2ab084)
@@ -0,0 +1,188 @@
+/*
+  Copyright (C) 2003-2017 Paul Brossier <piem@aubio.org>
+
+  This file is part of aubio.
+
+  aubio is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  aubio is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+/* This algorithm was developed by A. de Cheveigné and H. Kawahara and
+ * published in:
+ *
+ * de Cheveigné, A., Kawahara, H. (2002) "YIN, a fundamental frequency
+ * estimator for speech and music", J. Acoust. Soc. Am. 111, 1917-1930.
+ *
+ * see http://recherche.ircam.fr/equipes/pcm/pub/people/cheveign.html
+ */
+
+#include "aubio_priv.h"
+#include "fvec.h"
+#include "mathutils.h"
+#include "cvec.h"
+#include "spectral/fft.h"
+#include "pitch/pitchyinfast.h"
+
+struct _aubio_pitchyinfast_t
+{
+  fvec_t *yin;
+  smpl_t tol;
+  smpl_t confidence;
+  fvec_t *tmpdata;
+  fvec_t *sqdiff;
+  fvec_t *kernel;
+  fvec_t *samples_fft;
+  fvec_t *kernel_fft;
+  aubio_fft_t *fft;
+};
+
+aubio_pitchyinfast_t *
+new_aubio_pitchyinfast (uint_t bufsize)
+{
+  aubio_pitchyinfast_t *o = AUBIO_NEW (aubio_pitchyinfast_t);
+  o->yin = new_fvec (bufsize / 2);
+  o->tmpdata = new_fvec (bufsize);
+  o->sqdiff = new_fvec (bufsize / 2);
+  o->kernel = new_fvec (bufsize);
+  o->samples_fft = new_fvec (bufsize);
+  o->kernel_fft = new_fvec (bufsize);
+  o->fft = new_aubio_fft (bufsize);
+  o->tol = 0.15;
+  return o;
+}
+
+void
+del_aubio_pitchyinfast (aubio_pitchyinfast_t * o)
+{
+  del_fvec (o->yin);
+  del_fvec (o->tmpdata);
+  del_fvec (o->sqdiff);
+  del_fvec (o->kernel);
+  del_fvec (o->samples_fft);
+  del_fvec (o->kernel_fft);
+  del_aubio_fft (o->fft);
+  AUBIO_FREE (o);
+}
+
+/* all the above in one */
+void
+aubio_pitchyinfast_do (aubio_pitchyinfast_t * o, const fvec_t * input, fvec_t * out)
+{
+  const smpl_t tol = o->tol;
+  fvec_t* yin = o->yin;
+  const uint_t length = yin->length;
+  uint_t B = o->tmpdata->length;
+  uint_t W = o->yin->length; // B / 2
+  fvec_t tmp_slice, kernel_ptr;
+  smpl_t *yin_data = yin->data;
+  uint_t tau;
+  sint_t period;
+  smpl_t tmp2 = 0.;
+
+  // compute r_t(0) + r_t+tau(0)
+  {
+    fvec_t *squares = o->tmpdata;
+    fvec_weighted_copy(input, input, squares);
+#if 0
+    for (tau = 0; tau < W; tau++) {
+      tmp_slice.data = squares->data + tau;
+      tmp_slice.length = W;
+      o->sqdiff->data[tau] = fvec_sum(&tmp_slice);
+    }
+#else
+    tmp_slice.data = squares->data;
+    tmp_slice.length = W;
+    o->sqdiff->data[0] = fvec_sum(&tmp_slice);
+    for (tau = 1; tau < W; tau++) {
+      o->sqdiff->data[tau] = o->sqdiff->data[tau-1];
+      o->sqdiff->data[tau] -= squares->data[tau-1];
+      o->sqdiff->data[tau] += squares->data[W+tau-1];
+    }
+#endif
+    fvec_add(o->sqdiff, o->sqdiff->data[0]);
+  }
+  // compute r_t(tau) = -2.*ifft(fft(samples)*fft(samples[W-1::-1]))
+  {
+    fvec_t *compmul = o->tmpdata;
+    fvec_t *rt_of_tau = o->samples_fft;
+    aubio_fft_do_complex(o->fft, input, o->samples_fft);
+    // build kernel, take a copy of first half of samples
+    tmp_slice.data = input->data;
+    tmp_slice.length = W;
+    kernel_ptr.data = o->kernel->data + 1;
+    kernel_ptr.length = W;
+    fvec_copy(&tmp_slice, &kernel_ptr);
+    // reverse them
+    fvec_rev(&kernel_ptr);
+    // compute fft(kernel)
+    aubio_fft_do_complex(o->fft, o->kernel, o->kernel_fft);
+    // compute complex product
+    compmul->data[0]  = o->kernel_fft->data[0] * o->samples_fft->data[0];
+    for (tau = 1; tau < W; tau++) {
+      compmul->data[tau]    = o->kernel_fft->data[tau] * o->samples_fft->data[tau];
+      compmul->data[tau]   -= o->kernel_fft->data[B-tau] * o->samples_fft->data[B-tau];
+    }
+    compmul->data[W]    = o->kernel_fft->data[W] * o->samples_fft->data[W];
+    for (tau = 1; tau < W; tau++) {
+      compmul->data[B-tau]  = o->kernel_fft->data[B-tau] * o->samples_fft->data[tau];
+      compmul->data[B-tau] += o->kernel_fft->data[tau] * o->samples_fft->data[B-tau];
+    }
+    // compute inverse fft
+    aubio_fft_rdo_complex(o->fft, compmul, rt_of_tau);
+    // compute square difference r_t(tau) = sqdiff - 2 * r_t_tau[W-1:-1]
+    for (tau = 0; tau < W; tau++) {
+      yin_data[tau] = o->sqdiff->data[tau] - 2. * rt_of_tau->data[tau+W];
+    }
+  }
+
+  // now build yin and look for first minimum
+  fvec_set_all(out, 0.);
+  yin_data[0] = 1.;
+  for (tau = 1; tau < length; tau++) {
+    tmp2 += yin_data[tau];
+    if (tmp2 != 0) {
+      yin->data[tau] *= tau / tmp2;
+    } else {
+      yin->data[tau] = 1.;
+    }
+    period = tau - 3;
+    if (tau > 4 && (yin_data[period] < tol) &&
+        (yin_data[period] < yin_data[period + 1])) {
+      out->data[0] = fvec_quadratic_peak_pos (yin, period);
+      goto beach;
+    }
+  }
+  out->data[0] = fvec_quadratic_peak_pos (yin, fvec_min_elem (yin) );
+beach:
+  return;
+}
+
+smpl_t
+aubio_pitchyinfast_get_confidence (aubio_pitchyinfast_t * o) {
+  o->confidence = 1. - fvec_min (o->yin);
+  return o->confidence;
+}
+
+uint_t
+aubio_pitchyinfast_set_tolerance (aubio_pitchyinfast_t * o, smpl_t tol)
+{
+  o->tol = tol;
+  return 0;
+}
+
+smpl_t
+aubio_pitchyinfast_get_tolerance (aubio_pitchyinfast_t * o)
+{
+  return o->tol;
+}
Index: src/pitch/pitchyinfast.h
===================================================================
--- src/pitch/pitchyinfast.h	(revision 107037870a4ec56eeb2fdab92e153b96fd2ab084)
+++ src/pitch/pitchyinfast.h	(revision 107037870a4ec56eeb2fdab92e153b96fd2ab084)
@@ -0,0 +1,102 @@
+/*
+  Copyright (C) 2003-2017 Paul Brossier <piem@aubio.org>
+
+  This file is part of aubio.
+
+  aubio is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  aubio is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+/** \file
+
+  Pitch detection using YIN algorithm (fast implementation)
+
+  This algorithm was developed by A. de Cheveigne and H. Kawahara and
+  published in:
+
+  De Cheveigné, A., Kawahara, H. (2002) "YIN, a fundamental frequency
+  estimator for speech and music", J. Acoust. Soc. Am. 111, 1917-1930.
+
+  This implementation compute the autocorrelation function using time domain
+  convolution computed in the spectral domain.
+
+  see http://recherche.ircam.fr/equipes/pcm/pub/people/cheveign.html
+      http://recherche.ircam.fr/equipes/pcm/cheveign/ps/2002_JASA_YIN_proof.pdf
+
+*/
+
+#ifndef AUBIO_PITCHYINFAST_H
+#define AUBIO_PITCHYINFAST_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** pitch detection object */
+typedef struct _aubio_pitchyinfast_t aubio_pitchyinfast_t;
+
+/** creation of the pitch detection object
+
+  \param buf_size size of the input buffer to analyse
+
+*/
+aubio_pitchyinfast_t *new_aubio_pitchyinfast (uint_t buf_size);
+
+/** deletion of the pitch detection object
+
+  \param o pitch detection object as returned by new_aubio_pitchyin()
+
+*/
+void del_aubio_pitchyinfast (aubio_pitchyinfast_t * o);
+
+/** execute pitch detection an input buffer
+
+  \param o pitch detection object as returned by new_aubio_pitchyin()
+  \param samples_in input signal vector (length as specified at creation time)
+  \param cands_out pitch period candidates, in samples
+
+*/
+void aubio_pitchyinfast_do (aubio_pitchyinfast_t * o, const fvec_t * samples_in, fvec_t * cands_out);
+
+
+/** set tolerance parameter for YIN algorithm
+
+  \param o YIN pitch detection object
+  \param tol tolerance parameter for minima selection [default 0.15]
+
+*/
+uint_t aubio_pitchyinfast_set_tolerance (aubio_pitchyinfast_t * o, smpl_t tol);
+
+/** get tolerance parameter for YIN algorithm
+
+  \param o YIN pitch detection object
+  \return tolerance parameter for minima selection [default 0.15]
+
+*/
+smpl_t aubio_pitchyinfast_get_tolerance (aubio_pitchyinfast_t * o);
+
+/** get current confidence of YIN algorithm
+
+  \param o YIN pitch detection object
+  \return confidence parameter
+
+*/
+smpl_t aubio_pitchyinfast_get_confidence (aubio_pitchyinfast_t * o);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* AUBIO_PITCHYINFAST_H */
+
