Pitch Detection Methodology
how the detector actually works
This page documents exactly what the pitch detection engine on this site does, how raw microphone samples turn into a needle reading, and the physical limits of detecting pitch in a web browser. We state our implementation directly from the source code.
1. How Pitch Detection Works Here
This site does not use a mechanical strobe or a primitive zero-crossing counter. Instead, the tuner analyses incoming time-domain audio using the Normalized Square Difference Function (NSDF), an autocorrelation algorithm based on the McLeod Pitch Method (MPM).
When you enable the tuner, the browser requests access to your microphone and feeds the input into a Web Audio AnalyserNode configured with fftSize = 4096 and smoothingTimeConstant = 0.0. Every 50 milliseconds (an analysis cadence of approximately 20 Hz), the engine copies the time-domain frame, removes any DC bias, and correlates the window against delayed versions of itself.
The detector identifies key maxima (peaks) in the correlation curve that occur after the first zero crossing. To prevent octave drops or octave jumps, the fundamental period is selected as the first key maximum within 10% of the overall maximum value (a threshold of 0.90). The chosen peak is refined using sub-sample parabolic interpolation to estimate the fundamental frequency in Hertz.
2. The Analysis Window, Precisely
Two facts about browser audio capture are critical:
- The correlated window is not the analyser's entire frame: On the standard detection path, the correlation window is capped at 1,536 samples. At a standard 44.1 kHz sample rate, 1,536 samples represents approximately 34.8 milliseconds of audio.
- The window does not read the newest samples: In the Web Audio API,
getFloatTimeDomainDatareturns an array where index 0 holds the oldest sample in the buffer. Autocorrelation begins summing from index 0 across the lag range [minLag,maxLag].
3. The Decimated Low-Frequency Path
Detecting deep bass frequencies poses a fundamental mathematical constraint: period length. A low B on a 5-string bass (B0) vibrates at 30.87 Hz, which has a period of approximately 32.4 ms (1,428 samples at 44.1 kHz). In a standard 1,536-sample window, a 30.87 Hz wave completes only 1.08 cycles. When a note holds barely one cycle, harmonic overtones, string decay, and noise make reliable fundamental tracking impossible.
To resolve this, our engine implements a decimated low-frequency detection path for any preset whose lowest string sits below 70 Hz (including 5-string bass, 4-string double bass, cello, 7-string and 8-string guitars, baritone guitar, and drop C tuning):
- The raw 4,096-sample buffer is filtered through a 33-tap Blackman-windowed sinc anti-aliasing low-pass filter.
- The signal is decimated by a factor of 4, dropping the effective sample rate from 44.1 kHz to 11.025 kHz, yielding a 1,024-sample decimated frame.
- On this decimated path, the entire 1,024-sample frame is used as the correlation window (~92.9 ms), allowing the window to hold ~1.7 periods of B0 and over 2.3 periods of E1 (41.2 Hz).
4. Frequency Floors and False Readings
A global low-frequency floor is dangerous: if an instrument tuner listens down to 20 Hz, background room rumble and air conditioning noise will be captured and reported as an out-of-tune note.
Instead, our engine derives its detection floor per preset as:floor = lowestStringFrequency × 0.85
Any acoustic energy detected below this threshold, or any signal whose correlation clarity falls below 0.85 (or whose RMS level falls below the 0.008 noise gate), is rejected. The tuner reports no note rather than guessing or displaying a spurious reading.
5. Needle Smoothing and Cents
Musical pitch deviation is measured in cents. An equal-tempered semitone is divided into 100 cents, and an octave contains 1,200 cents. A reading of -10 cents means the string is flat (vibrating too slowly and requiring tightening); +10 cents means the string is sharp (vibrating too quickly and requiring loosening). A note is considered in-tune when deviation is within ±3 cents of the target frequency.
Because instantaneous microphone frames fluctuate from pluck attack transients and room reflections, the needle applies exponential smoothing:alpha = 1 - Math.exp(-dt / 0.08) (an 80 ms ballistics smoothing filter).
When a note decays into silence, the needle gently drifts toward center over a 150 ms decay window.
6. Practical Accuracy and Honest Limits
While parabolic peak interpolation computes fractional frequencies down to hundredths of a Hertz,we make no claim of laboratory frequency tolerance. In real rooms with physical instruments, practical accuracy is dictated by physics, not algorithms:
- Inharmonicity: Heavy, stiff strings (such as the low strings on short-scale basses) produce overtones that are slightly sharper than exact integer multiples of the fundamental.
- Attack pitch glide: Plucking a string hard stretches it, raising the pitch by 5 to 15 cents for the first 100 milliseconds before it settles into its true pitch.
- Room modes and reflections: Standing waves in small rooms can amplify specific harmonics while cancelling the fundamental.
7. Microphone Privacy
Your microphone stream is processed entirely in local device memory using the browser's native Web Audio API. Audio samples are never stored to disk, never recorded, and never uploaded to any server. The tuner creates zero network requests and stores no audio data or tuning history in localStorage.
8. Checklist: How to Get a Clean Reading
- Find a quiet room: Background television, conversation, and HVAC hum degrade correlation clarity.
- Mute all unplayed strings: Rest your palm or fingers across adjacent strings so they do not vibrate sympathetically.
- Pluck near the 12th fret: Plucking near the middle of the string emphasizes the fundamental frequency; plucking right next to the bridge generates harsh, high-order harmonics that confuse pitch trackers.
- Let the note ring: Strike the string with moderate force and wait one second for the attack pitch glide to settle before checking the needle.
- Keep your microphone 15–30 cm away: Placing the microphone 6 to 12 inches from the instrument body provides adequate gain without clipping the input stage.