pitch detection algorithms in C++
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
example Add option to plot with lags Oct 14, 2018
LICENSE Add MIT license Apr 30, 2018
README.md Improve readme Oct 8, 2018


Pitch detection algorithms

A collection of C++ pitch detection algorithms.

  • McLeod Pitch Method
  • YIN
  • Autocorrelation
  • DFT
  • Goertzel

MPM performs best on real musical instruments and voice; see pitcha and transcribe.


Depends on ffts.

$ make
$ FFT_FLAG="-DPORTABLE_XCORR" make # build with no FFTS
$ sudo make install

Use with #include <pitch_detection.h> and the flag -lpitch_detection.

To use in your code:

$ head -n1 main.cpp
#include <pitch_detection.h>
$ g++ main.cpp -lpitch_detection

NB: using input vectors of size power-of-2 will perform better due FFT optimizations.

Sinewave example

Depends on gflags:

$ sudo dnf install gflags-devel
$ make examples


$ ./bin/sinewave --help
Flags from example/sinewave.cpp:
    -algo (Algorithm to test) type: string default: "mpm"
    -frequency (Sinewave frequency in Hz) type: double default: -1
    -noise (Noise to introduce in %) type: double default: 0
    -sample_rate (Sample rate in Hz) type: uint64 default: 48000
    -size (Sine wave size (single channel)) type: uint64 default: 4096