Written by Vincent Sullivan | Last updated: June 2026
What This Page Explains
This page documents the exact technical mechanism behind the Online Pitch Detector on OnlinePitchDetector.com. It explains what the tool measures, how each stage of the detection pipeline works, what accuracy the result achieves, and what the tool cannot determine. For plain-language answers about what your result means, see the FAQ.
What the Tool Measures
The Online Pitch Detector measures the fundamental frequency (F0) of a sound captured through your microphone — the rate of the periodic vibration that determines the perceived pitch of a tone, expressed in Hertz (Hz).
It then maps the detected F0 to:
- The nearest musical note in equal temperament (A4 = 440 Hz)
- The cents deviation — how many cents sharp or flat the detected frequency is from that note’s exact equal temperament frequency
These three values together — Hz, note name, cents — define where a pitch sits with full technical precision.
Equal temperament note frequencies (reference, octave 4):
| Note | Frequency (Hz) |
|---|---|
| C4 (Middle C) | 261.63 |
| D4 | 293.66 |
| E4 | 329.63 |
| F4 | 349.23 |
| G4 | 392.00 |
| A4 | 440.00 |
| B4 | 493.88 |
The Detection Pipeline — Step by Step
Step 1 — Microphone Permission and MediaStream Capture
The browser requests microphone permission via getUserMedia(). Once granted, a live MediaStream is opened at the system’s native sample rate — typically 44,100 Hz or 48,000 Hz — and connected to a MediaStreamAudioSourceNode within an AudioContext.
The microphone stream is never recorded, never stored in any persistent form, and never transmitted over the network. For full details on audio data handling, see the Data Security page.
Step 2 — FFT Analysis via AnalyserNode
The MediaStreamAudioSourceNode feeds into an AnalyserNode configured with a 2048-sample FFT window. The AnalyserNode performs a Fast Fourier Transform on the incoming audio at regular intervals, converting the time-domain signal into a frequency-domain spectrum.
| Parameter | Value | Effect |
|---|---|---|
| FFT size | 2048 samples | Frequency resolution ~21.5 Hz per bin at 44,100 Hz |
| Analysis rate | ~23 ms per frame | Real-time update rate |
| Smoothing constant | 0.8 | Reduces frame-to-frame jitter in display |
The FFT spectrum is used as a preliminary tool for noise floor assessment and for confirming voiced/unvoiced status of the incoming signal.
Step 3 — YIN Autocorrelation F0 Detection
The YIN algorithm (de Cheveigné and Kawahara, 2002) is applied to the time-domain audio buffer for fundamental frequency detection. YIN uses an autocorrelation-based approach with a critical enhancement: the difference function rather than raw autocorrelation, which reduces the tendency of standard autocorrelation to return the octave rather than the true fundamental.
The YIN difference function: For a signal x(t) and lag τ:
d(τ) = Σ [x(t) − x(t + τ)]²
The lag τ at which d(τ) reaches its first local minimum below a threshold — the fundamental period — is identified as the pitch period.
F0 is calculated from the detected period:
F0 (Hz) = Sample rate ÷ Lag at minimum d(τ) (samples)
Worked example: If the minimum of the difference function is found at lag 100 samples at 44,100 Hz:
F0 = 44,100 ÷ 100 = 441 Hz ≈ A4 + 3.9 cents
The lag search is bounded to the musically relevant range:
Minimum lag = Sample rate ÷ Maximum F0 = 44,100 ÷ 1,100 ≈ 40 samples
Maximum lag = Sample rate ÷ Minimum F0 = 44,100 ÷ 80 ≈ 551 samples
This covers the range from approximately E2 (82 Hz) to C6 (1,047 Hz) — the full practical range of most musical instruments and voices.
Step 4 — Musical Note Mapping
The detected F0 in Hz is mapped to the nearest musical note using the equal temperament formula:
Semitones from A4 = 12 × log₂(F0 ÷ 440)
Worked example for F0 = 441 Hz:
Semitones from A4 = 12 × log₂(441 ÷ 440) = 12 × 0.00392 ≈ 0.047
The nearest integer semitone is 0 → A4.
The note name is determined from the semitone offset:
- 0 semitones from A4 → A4
- −12 → A3
- +2 → B4
- −9 → C4 (Middle C)
Step 5 — Cents Deviation Calculation
Once the nearest note is identified, the cents deviation — how far the detected frequency sits from the note’s exact equal temperament frequency — is calculated:
Cents deviation = 1,200 × log₂(F0 ÷ f_target)
Where f_target is the exact equal temperament frequency of the nearest note.
Worked example for F0 = 441 Hz, nearest note A4 (440 Hz):
Cents deviation = 1,200 × log₂(441 ÷ 440) = 1,200 × 0.00392 ≈ +4.7 cents
The result displays: A4 (+5 cents) — sharp of A4 by approximately 5 cents.
Practical significance of cents deviation:
| Deviation | Perceptual Effect |
|---|---|
| 0–5 cents | Imperceptible to most listeners |
| 5–15 cents | Perceptible to trained musicians |
| 15–30 cents | Clearly out of tune to most listeners |
| 50 cents | Quarter-tone flat or sharp |
| 100 cents | One full semitone off |
Step 6 — Real-Time Display and Refresh
The detection pipeline runs at approximately 20–30 frames per second, updating the Hz value, note name, and cents deviation in real time. A smoothing function reduces display jitter caused by frame-to-frame variation in F0 — typical in natural sustained tones, which have slight natural pitch variation from vibrato, breath support fluctuation, or bow pressure variation.
Accuracy
Under typical conditions — a quiet environment, a sustained tone, and a functional microphone — the tool achieves F0 detection accuracy of approximately ±2–5 cents across the range of 100–800 Hz.
Accuracy is reduced by:
- Background noise — ambient sound in the 80–1,100 Hz range competes with the target tone and reduces difference function peak clarity
- OS audio processing — automatic gain control (AGC) and noise suppression alter the captured waveform before it reaches the browser
- Consumer microphone low-frequency response — roll-off below 100–150 Hz increases uncertainty for bass instruments and low male voices
- Short or inconsistent phonation — the YIN algorithm requires a sustained tone of at least 100–200 ms for reliable detection
- Breathy or airy tone quality — aperiodic sound components reduce the sharpness of the difference function minimum
What This Tool Cannot Determine
Polyphonic pitch — chords, intervals, or two simultaneous notes The YIN algorithm and this tool’s pipeline are designed for monophonic signals — a single tone at a time. Playing a chord or two simultaneous notes will produce an unreliable or averaged result. For chord identification, a polyphonic detection tool is required.
Octave errors are possible The YIN difference function reduces but does not eliminate octave errors. In conditions of low SNR or with tones that have very strong second harmonics (e.g. certain bowed string tones, some flute tones), the algorithm may return F0 at half the true frequency (one octave too low) or double the true frequency (one octave too high). Results that seem to be exactly an octave off from the expected pitch should be treated as likely octave errors.
Absolute tuning reference The tool detects the frequency of the incoming sound. It does not correct for a non-standard reference pitch. If your instrument or software is tuned to A4 = 432 Hz or another non-standard pitch, the cents deviation will be calculated relative to A4 = 440 Hz and will reflect the offset accordingly.
Vibrato centre pitch For tones with significant vibrato, the displayed F0 reflects the instantaneous frequency at each analysis frame — not the mean pitch of the vibrato cycle. For vibrato-averaged pitch, multiple readings should be averaged manually.
Related Pages
- FAQ — plain-language answers about pitch detection results and common measurement questions
- Troubleshooting — what to do if the tool fails to detect, shows octave errors, or produces unstable readings
- Data Security — how microphone audio is processed and why it never leaves your device
- About OnlinePitchDetector.com — who runs this site and why it was built
Written by Vincent Sullivan, founder of OnlinePitchDetector.com. Last updated: June 2026.