I'm a solo developer at a small studio, and I recently shipped a guitar tuner and metronome called Maestro. The tuner was the part I got wrong first, so this post is about that.
The naive approach fails on real instruments
The obvious way to build a tuner: take a window of microphone samples, run an FFT, pick the tallest peak, convert to a note. It works on a sine wave. On a real guitar it doesn't, because the loudest bin is often the 2nd or 3rd harmonic, not the fundamental. A low E (about 82 Hz) will happily read as the E an octave up, or as a B, depending on the pluck.
What I used: the McLeod Pitch Method (MPM)
MPM computes a normalized square-difference autocorrelation of the window. Instead of looking for the biggest peak in frequency space, it looks for repeating structure in time, and normalizes by signal energy at each lag so quiet tails don't lose to loud attacks.…