How the Guitar Tuner Detects Pitch
AnyTool Guitar Tuner runs entirely on the native Web Audio API plus navigator.mediaDevices.getUserMedia. The microphone stream feeds a MediaStreamAudioSourceNode connected to an AnalyserNode (fftSize 4096, smoothing 0) that is deliberately not wired to the destination, so there is no feedback. On every animation frame the tuner reads the raw waveform with getFloatTimeDomainData and runs the well-known ACF2+ autocorrelation algorithm: it first computes the RMS and rejects frames below a threshold as silence, trims near-silent samples from both edges of the buffer, then correlates the signal with delayed copies of itself to find the lag at which it best repeats. The first strong peak after the initial dip is the period; parabolic interpolation around that peak refines it to a sub-sample value, and the sample rate divided by the period yields the fundamental frequency. A short running median over recent frames removes octave-jump spikes and an exponential moving average steadies the readout, after which the frequency is mapped to the nearest equal-tempered note (A4 = 440 Hz) and a cents deviation.
- getUserMedia → MediaStreamAudioSourceNode → AnalyserNode (fftSize 4096), not connected to output
- ACF2+ autocorrelation on getFloatTimeDomainData with RMS-based silence rejection
- Parabolic interpolation around the correlation peak for sub-cent period accuracy
- Median + exponential moving average smoothing to kill jitter and octave jumps
- Frequency → nearest note (A4 = 440) + cents (100 cents = one semitone), all in-browser
