"Auto-tune online" sounds like a solved problem until you try to make one that runs on a phone, in a browser, on a vocal recorded in a kitchen. This is how the free Neural Auto-Tune on SongUp AI works under the hood. I work on it, and everything below comes from the source.
The whole thing is three pure functions on Float32Arrays, run on the full vocal at once (no AudioWorklet tricks), so they can be unit-tested in Node:
trackPitch(vocal) → MIDI pitch every 10 ms correctionCurve(track, key) → pitch shift in semitones per frame psola(vocal, track, shift) → the tuned vocal 1. Pitch tracking: YIN on a downsampled copy
- The vocal is downsampled to about 11 kHz (4× for 44.1 kHz files). Singing fundamentals live well below that, and YIN gets four times cheaper.
- YIN runs every 10 ms with lags covering roughly 65 Hz to 1 kHz, then a parabolic refinement of the best lag.
- A level gate skips silence. It used to be fixed at about −48 dBFS; a quiet recording peaking at −45 dBFS sat entirely under it, so nothing was tracked and the tool silently did nothing. The gate now follows the file's own peak.
- A median of 5 over voiced neighbours removes single-frame octave slips, and voiced runs shorter than 40 ms are thrown away as noise.
2. Guess the key from the melody
Users don't know their key, and a wrong key is the #1 reason auto-tune sounds "off". So the tool builds a histogram of how long each pitch class is sung and correlates it against the major and minor profiles (Krumhansl–Schmuckler). The result ("Key heard in your vocal: A minor") pre-selects one of 12 keys; the user can override it, and pick one of 7 scales: Chromatic, Major, Minor, Pentatonic, Blues, Dorian, Mixolydian.
3. The correction curve (where the musical decisions are)
For each frame, the target is the nearest note of the chosen scale. Two details make the difference between "tuned" and "broken":
Hysteresis against vibrato. A singer 40 cents flat with 30 cents of vibrato sits right on the boundary between two scale notes. A naive nearest-note picker made that note trill 18 times in 6 seconds. Now a new target has to hold for 80 ms, or be a clear jump of more than 1.3 semitones, and is then back-dated to where it began, so fast legato runs still land.
Retune speed as a one-pole glide. The shift approaches the target with a time constant
tau = 0.002 + (1 - speed)^1.5 * 0.25 // seconds At speed 1 it snaps instantly (the robotic effect); lower values glide over up to ~250 ms so slides and vibrato survive. The presets are Natural (25), Moderate (55) and Hard Tune (85), plus a custom slider.
4. TD-PSOLA, so the voice still sounds like you
The shift is applied with time-domain PSOLA: grains two periods long, taken one period apart and laid down period / ratio apart. That moves the pitch while keeping the formants, so you don't get the chipmunk effect of plain resampling. Unvoiced parts and notes already in tune come out sample-identical, which is the best possible "do no harm" guarantee.
Two small fixes that took real listening to find:
- Each grain's half-length is its period or the gap to a neighbouring pitch mark, whichever is longer, so windows always sum to at least 1 (no holes after a breath).
- Files ending mid-note produced a tick in the last 1.5 ms. The last 10 ms now hand over to the dry signal.
5. Monitoring and export
Preview plays the tuned vocal (optionally over a beat, level-matched first) with a live cents meter. The export is rendered in an OfflineAudioContext and peak-limited to −1 dBFS, because vocal plus beat can go over full scale.
What it can't do
If a note is two semitones out, any auto-tune will sound processed. It also needs a solo vocal: with music under it, YIN tracks the loudest thing, which may not be the voice. The tool tells you when it couldn't hear a clear singing voice instead of returning garbage.
If you build one: track first, decide musically second, shift last. And keep all three as pure functions so you can test them with synthetic sine sweeps.
Disclosure: I work on SongUp AI. This post was drafted with AI help and checked against the source code.