Pitch shift algorithms
Repo audiojs/shift, read from GitHub 1 min ago. audiojs has not joined Take My Repo.
audiojs/shift is a public repo on GitHub by audiojs. Pitch shift algorithms. It declares the MIT license on GitHub. It is written mainly in JavaScript, has 10 stars and last changed on 2026-11-21. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-21.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
Try it in the browser: Pitch and tempo changer. Runs on this package, nothing is uploaded.
Canonical pitch-shifting algorithms in functional JavaScript.
Frequency-domain: vocoder, phaseLock, transient, formant, sms, hpss.
Time-domain: ola, wsola, psola, granular, sample, delay.
Source-filter: lpc.
Consistent unified API: batch, stream, multi-channel — 15 algorithms.
Part of the audiojs ecosystem.
npm install @audio/shift
Each algorithm also ships standalone — npm install @audio/shift-transient, @audio/shift-lpc, etc. — for installs that need only one.
import { transient } from '@audio/shift' // Batch let pitched = transient(audio, { semitones: 5 }) // Stream let write = transient({ ratio: 1.5 }) let output = write(inputBlock) let tail = write() // flush // Stereo let [L, R] = transient([left, right], { ratio: 1.5 })
write/flush is the same shape everywhere, but not every algorithm streams incrementally. vocoder, phaseLock, transient, formant, and sms emit audio frame-by-frame as it arrives. Every other algorithm — ola, psola, wsola, granular, paulstretch, hpss, sample, hybrid, delay, lpc — buffers the whole input and returns everything on the matching flush call; the API is uniform, the latency isn't.
| Domain | Best for | shift | |
|---|---|---|---|
| pitchShift | auto | content-aware default | 1.755 |
| transient | STFT | music with percussion ★ | 1.755 |
| phaseLock | STFT | general music | 1.755 |
| vocoder | STFT | simple tonal | 1.553 |
| formant | STFT | voice (no chipmunk) | 1.573 |
| hpss | STFT | mixed music (drums+tonal) | 1.487 |
| sms | sinusoidal | harmonic/tonal | 1.701 |
| paulstretch | STFT | ambient, extreme shifts | 2.221 |
| wsola | time | speech, low-latency | 1.674 |
| psola | time | speech, mono voice | 1.766 |
| delay | delay-line | real-time, harmonizer | 1.610 |
| ola | time | baseline | 2.025 |
| granular | time | creative textures | 2.256 |
| sample | time | sampler/tracker playback | 1.614 |
| hybrid | hybrid | mixed dynamic material | 1.824 |
| lpc | source-filter | speech, formant filter | 1.679 |
Frequency-domain algorithms shift bins natively. ola/wsola/psola stretch time via stretch, then sinc-resample back to pitch. granular, sample, delay, and lpc shift natively — no stretch-then-resample stage. shift = log-magnitude distance to canonical reference (lower is better). Run npm run quality for all metrics.
All algorithms accept ratio (1.5 = +7 semitones, 2 = octave) and semitones. frameSize (2048) / hopSize (frameSize/4) apply to the STFT family, ola, wsola, and hybrid; granular (grainSize), delay (window/tolerance), lpc (frameSize alone, no hopSize), and sample/psola (no frame parameter) each use their own — see each section.
Every algorithm's streaming output is numerically identical to its batch output on the same input, byte for byte. For ola, psola, wsola, granular, paulstretch, hpss, sample, hybrid, delay, and lpc, that's automatic — the stream writer buffers the whole input and runs the batch code path once at flush(). For vocoder, phaseLock, transient, formant, and sms, it's a real per-frame guarantee: each frame renormalizes its own energy independently of every other frame, so a batch run and a run fed one differently-chunked block at a time land on the exact same output.
That per-frame renormalization also replaces whole-signal loudness correction for those five: none of them apply a post-hoc RMS match (matchGain) anymore, and loudness still lands within ~1 dB of the input (measured −0.98 to +0.10 dB across the family on a plain sine). lpc is the exception: its excitation-domain repitching can drift level with the AR envelope's own gain, so it matches each channel's level to its input's once a call, one gain a channel.
pitchShiftContent-aware auto-selector. Picks: voice/speech → psola, tonal → sms, else → transient.
import pitchShift from '@audio/shift' pitchShift(audio, { semitones: 5 }) pitchShift(audio, { ratio: 1.5, content: 'voice' }) pitchShift(audio, { ratio: 2, method: 'formant' }) pitchShift(audio, { ratio: 1.5, method: 'delay' })
| Param | Default | |
|---|---|---|
content |
music |
music, voice/speech, tonal |
method |
auto | Force any algorithm by name, including 'delay'/'lpc' |
formant |
false |
Wrap in formant preservation |
formant: true together with an explicit, different method throws instead of silently overriding it — pass just one.
onDecision is called with the method chosen and why ({ method, reason, ratio, semitones, content, formant }), once a call: a channel array, or a stream of channels, is one take, so it is called once for all its channels, a stream's at its first write. A stream at a ratio of 1 passes its input through and does not call it.
transientPeak-locked phase vocoder with spectral-flux transient detection. On transient frames, synthesis phase resets to analysis phase, preserving attacks. Between transients, behaves like phaseLock.
import { transient } from '@audio/shift' transient(audio, { ratio: 1.5 }) transient(audio, { semitones: 5, transientThreshold: 2.0 })
| Param | Default | |
|---|---|---|
transientThreshold |
1.5 |
z-score over log-flux EMA (higher = fewer resets) |
Preserves phase coherence, partial structure, attack localization on detected transients.
Destroys formants; misses quiet transients at too-high threshold.
| f0 err | THD% | alias | attack corr | formant dist | phase coh | shift |
|---|---|---|---|---|---|---|
| 0.00 | 0.0 | 0.000 | 0.984 | 1.423 | 0.999 | 1.755 |
Byte-identical to phaseLock on every fixture in the quality suite — the onset detector's z-score gate never fires on them, not even the plucked string's attack. It's built for real percussive onsets (see the demo's rock-beat fixture, which npm run quality doesn't score); on this synthetic suite it's a phaseLock with unused wiring.
Use when: Music with drums — the default choice.
Not for: Voice where formant preservation matters.
phaseLockLaroche-Dolson peak-locked phase vocoder. Peaks scatter to shifted bins; non-peak bins lock their phase relative to the nearest peak, keeping the vertical phase relationship inside each sinusoidal lobe intact.
import { phaseLock } from '@audio/shift' phaseLock(audio, { ratio: 1.5 })
Preserves phase coherence around peaks, partial structure.
Destroys transients (still smeared, less than vocoder), formants.
| f0 err | THD% | alias | attack corr | formant dist | phase coh | shift |
|---|---|---|---|---|---|---|
| 0.00 | 0.0 | 0.000 | 0.984 | 1.423 | 0.999 | 1.755 |
Use when: General music — the "try this first" phase vocoder.
Not for: Music with drums (use transient), voice (use formant).
vocoderSMB/Bernsee bin-shift. Computes true instantaneous frequency per bin from consecutive-frame phase advance, scatters peaks to shifted bins, accumulates synthesis phase at the shifted frequency.
import { vocoder } from '@audio/shift' vocoder(audio, { ratio: 1.5 })
Preserves dominant-partial pitch, long-horizon phase per bin.
Destroys transients, vertical phase coherence ("phasiness"), formants.
| f0 err | THD% | alias | attack corr | formant dist | phase coh | shift |
|---|---|---|---|---|---|---|
| 0.00 | 0.0 | 0.000 | 0.981 | 1.158 | 0.928 | 1.553 |
Phase coh 0.928 from independent per-bin phase accumulation — no inter-bin locking. Best shift score among the general phase vocoders — the simpler scatter avoids the peak-locked family's own assignment overhead on these fixtures.
Use when: Simple tonal material, educational baseline.
Not for: Music with percussion, voice.
formantCepstral envelope preservation wrapping a peak-locked vocoder. Extracts spectral envelope via cepstral liftering from temporally-smoothed magnitude, flattens the spectrum, applies peak-locked pitch shift on the flat residual, re-imposes the original envelope.
import { formant } from '@audio/shift' formant(audio, { semitones: 5 }) formant(audio, { ratio: 0.75, envelopeWidth: 16 })
| Param | Default | |
|---|---|---|
envelopeWidth |
max(8, round(sr/1378)), ≤ N/4 |
Cepstrum lifter cutoff (quefrency bins) |
Preserves formant envelope (absolute Hz), vocal-tract character.
Destroys transients (same as vocoder); risks cepstral ringing on sparse spectra.
| f0 err | THD% | alias | attack corr | formant dist | phase coh | shift |
|---|---|---|---|---|---|---|
| 0.00 | 0.0 | 0.000 | 0.987 | 0.765 | 1.000 | 1.573 |
Best formant dist in the collection by construction — the envelope is explicitly separated and re-applied. Also the best phase coherence (1.000): the correction reshapes magnitude only, so it inherits the peak-locked vocoder's phase tracking untouched, and gains a hair over phaseLock itself.
Use when: Voice shifting without chipmunk / giant artifact.
Not for: Percussion-heavy material (transients smear).
hpssFitzgerald median-filter harmonic/percussive separation. Time-axis and frequency-axis medians produce soft Wiener masks splitting the spectrogram. Harmonic component is vocoder-shifted; percussive component passes through with original phase.
import { hpss } from '@audio/shift' hpss(audio, { ratio: 1.5 }) hpss(audio, { ratio: 1.5, hpssTimeWidth: 31, hpssFreqWidth: 31 })
| Param | Default | |
|---|---|---|
hpssTimeWidth |
17 |
Median window width (frames) |
hpssFreqWidth |
17 |
Median window width (bins) |
hpssPower |
2 |
Soft-mask exponent |
Preserves percussive onset locations (unshifted) and harmonic pitch (shifted).
Destroys signal quality at ambiguous mask boundaries (leakage in both directions).
| f0 err | THD% | alias | attack corr | formant dist | phase coh | shift |
|---|---|---|---|---|---|---|
| 0.00 | 0.0 | 0.053 | 0.998 | 1.207 | 0.928 | 1.487 |
Best overall shift score — keeping percussion unshifted sidesteps most artifacts. It also has the best attack correlation in the whole collection (0.998): the percussive component's phase is never touched, so a plucked-string attack survives more faithfully than even the time-domain similarity-search methods. Alias 0.053 is residual harmonic energy leaking through the percussive mask.
Use when: Mixed music where drums should stay stationary while melody shifts.
Not for: Solo tonal material (unnecessary separation overhead).
smsSpectral Modeling Synthesis. Parabolic-interpolated peak picking builds sinusoidal tracks (freq, mag, phase); each peak's lobe is copied intact to round(f·ratio). Stochastic residual shifts to ratio-scaled bins with analysis phase.
import { sms } from '@audio/shift' sms(audio, { ratio: 2 }) sms(audio, { ratio: 1.5, maxTracks: 40 })
| Param | Default | |
|---|---|---|
maxTracks |
Infinity |
Max simultaneous sinusoidal tracks |
minMag |
1e-4 |
Peak detection threshold (linear) |
Preserves formant envelope (lobes scale freely with peaks), harmonic structure, tonal clarity.
Destroys transients, noise-like textures (absorbed into residual), polyphony beyond maxTracks.
| f0 err | THD% | alias | attack corr | formant dist | phase coh | shift |
|---|---|---|---|---|---|---|
| 0.00 | 0.0 | 0.002 | 0.963 | 1.845 | 0.929 | 1.701 |
Lower attack corr (0.963) because sinusoidal modeling smooths onset transients into the residual.
Use when: Sustained tonal / harmonic instruments, vowels.
Not for: Percussion, noise-heavy material.
paulstretchLarge-frame (16k) phase randomization. Magnitudes pulled from source bins at k/ratio; phases drawn from a seeded PRNG every frame. Destroys temporal structure by design.
import { paulstretch } from '@audio/shift' paulstretch(audio, { ratio: 1.5 }) paulstretch(audio, { ratio: 1.5, seed: 42 })
| Param | Default | |
|---|---|---|
seed |
fixed (0x1f123bb5) |
32-bit PRNG seed for the per-frame phase draw |
Deterministic: the same seed (the shipped default, or one you pass) always reproduces the same phase sequence and therefore byte-identical output. Pass seed to get a different, still-reproducible draw.
Preserves long-term magnitude-spectrum statistics.
Destroys phase, transients, rhythm — by design.
| f0 err | THD% | alias | attack corr | formant dist | phase coh | shift |
|---|---|---|---|---|---|---|
| 0.00 | 0.2 | 0.230 | 0.935 | 7.371 | 0.518 | 2.221 |
Worst formant dist by a wide margin (7.371 — the next-worst is granular at 3.486) because random phases smear spectral energy across the frame; the smear is the aesthetic. Alias 0.230 is the same smear leaking past Nyquist.
Use when: Ambient/drone textures, extreme shift ratios.
Not for: Anything requiring temporal precision.
wsolaWSOLA time-stretch + sinc resample. Searches each grain position ±tolerance samples for maximum cross-correlation with the previous grain's tail, eliminating phase cancellation before resampling to the target pitch.
import { wsola } from '@audio/shift' wsola(audio, { ratio: 0.85 }) wsola(audio, { ratio: 1.5, tolerance: 512 })
| Param | Default | |
|---|---|---|
tolerance |
frameSize/4 |
Similarity search radius (±samples) |
Preserves local waveform shape, attack envelopes.
Destroys formants (shifted by resample), phase coherence across long spans.
| f0 err | THD% | alias | attack corr | formant dist | phase coh | shift |
|---|---|---|---|---|---|---|
| 1.67 | 0.1 | 0.005 | 0.995 | 2.358 | 0.864 | 1.674 |
f0 err 1.67 Hz from sinc resample quantization (time-domain algorithms round the stretch ratio to grain boundaries). Attack corr 0.995 ties delay for second place — only hpss's untouched percussive pass-through scores higher.
Shifted up, the last grains read past the take into silence, so the level over the output's last frames moves, as at any stop followed by silence: over the last 1024 frames against the output's middle, a held tone moves −2.9 to +0.3 dB at +1 semitone, −9.1 to −0.6 dB at +12 and −10.1 to −2.4 dB at +24, by where the last grain falls (node scripts/ends.js fade: tones of 110 to 1000 Hz at 32 take lengths, 22.05 to 96 kHz). How early or late the output runs follows the rate and the search (node scripts/ends.js lead): an octave up 296 to 724 frames early, 5 semitones up from 128 frames late to 248 early, shifted down 552 to 1536 frames late at −5 and −12 semitones. The take's last sound plays on past its end, inside the audio manifest's declared tail.
Use when: Speech, low-latency, anywhere the phase vocoder's frame latency is unacceptable.
Not for: Polyphonic music with sustained tones.
psolaPSOLA time-stretch + sinc resample. Autocorrelation detects pitch periods; two-period Hann grains are placed at pitch-synchronous intervals, reducing the grain-boundary artifacts plain WSOLA gets on voiced monophonic material. The final resample rescales the whole spectrum by ratio, so formants move with f0 exactly as they do for wsola — this is a smoother stretch, not formant preservation.
import { psola } from '@audio/shift' psola(audio, { ratio: 0.75, sampleRate: 48000 }) psola(audio, { ratio: 1.5, minFreq: 100, maxFreq: 400 })
| Param | Default | |
|---|---|---|
sampleRate |
44100 |
For pitch detection range |
minFreq |
80 |
Lowest expected pitch (Hz) |
maxFreq |
500 |
Highest expected pitch (Hz) |
Preserves waveform-per-period shape, voiced-speech naturalness.
Destroys formants (same resample-driven shift as wsola), polyphony (assumes single pitch contour), unvoiced regions (pitch-mark jitter); falls back to plain WSOLA internally when no reliable pitch period is found.
| f0 err | THD% | alias | attack corr | formant dist | phase coh | shift |
|---|---|---|---|---|---|---|
| 0.66 | 0.2 | 0.005 | 0.941 | 2.336 | 0.998 | 1.766 |
Phase coherence 0.998 — pitch-synchronous grains align with the waveform period almost perfectly, just short of formant's 1.000. Lower attack corr (0.941) from pitch-mark jitter on non-periodic onsets.
The take is stretched followed by silence of its own, so its grains and the stretch's WSOLA run on into it: what the take rings past its end lies within the audio manifest's declared tail, and a host's padding moves nothing over the take. Which of pitch-synchronous grains, WSOLA and their blend the stretch chooses is the installed @audio/stretch-psola's to decide. From 1.2.4 on it takes its voicing shares up to the input's last sample that is not 0, so the exact zeros after the take count in none; a dithered tail is sound to it, and its length counts. An earlier version counts this silence of psola's own in its shares too, so the choice is made on the take and its silence, and a short voice can be blended with WSOLA where alone it is stretched pitch-synchronously.
Use when: Monophonic speech, solo voice, single melodic instrument.
Not for: Polyphonic material, chords, or anywhere formants must stay put (use lpc).
delayCanonical delay-line (harmonizer) pitch shift — the method behind hardware harmonizers (Eventide H910 lineage, Lexicon "rotating tape head"). Two read taps sweep a modulated delay window at rate ratio, alternating through a Hann crossfade a half-cycle apart. Each time a tap wraps, it splices at whichever lag offset in the search window best correlates with the still-live tap ("intelligent splicing"), which is what keeps the join from phase-slipping the carrier.
import { delay } from '@audio/shift' delay(audio, { ratio: 1.5 }) delay(audio, { ratio: 1.5, window: 1024, tolerance: 128 })
| Param | Default | |
|---|---|---|
window |
2048 |
Delay-line length (samples); trades flutter rate against transient smear |
tolerance |
window/4 |
Splice search radius (±samples) |
Preserves duration, pitch accuracy — no grain or frame to quantize the shift against; state is bounded by window samples, the shape a real-time implementation needs.
Destroys clean sustain on wideband or polyphonic material — the two taps share one delay line, so simultaneous partials all splice through the same wrap points and beat against each other; audible as mild flutter at the crossfade rate.
| f0 err | THD% | alias | attack corr | formant dist | phase coh | shift |
|---|---|---|---|---|---|---|
| 1.10 | 0.1 | 0.028 | 0.995 | 2.445 | 0.940 | 1.610 |
f0 err 1.10 Hz sits at the measurement floor — nothing here to quantize pitch against. Formant dist 2.445 is unremarkable: the shared delay line resamples the envelope exactly like a time-domain stretch does, no better.
The streaming write/flush wrapper shipped here buffers the whole input like hpss/hybrid (see Runtime behavior) — the algorithm's own state is bounded by window samples, but nothing yet exposes that as incremental output.
Use when: Real-time-shaped, lowest-latency time-domain shifting, or the hardware-harmonizer flutter is the wanted character.
Not for: Dense chords or polyphony (the splice artifacts stack per partial).
olaPlain OLA time-stretch + sinc resample. Overlap-add without similarity search — the baseline the others improve on.
import { ola } from '@audio/shift' ola(audio, { ratio: 1.5 })
Preserves amplitude envelope.
Destroys pitch accuracy, formants, transients, phase coherence.
| f0 err | THD% | alias | attack corr | formant dist | phase coh | shift |
|---|---|---|---|---|---|---|
| 38.33 | 0.2 | 0.004 | 0.980 | 2.342 | 0.995 | 2.025 |
f0 err 38.33 Hz — worst by far. Without similarity search, grains land at arbitrary phase offsets causing destructive interference that shifts the perceived pitch.
Shifted up, an output frame mixes grains read ahead of it (an octave up, output frame i reads input frames i to i + N/2), so the output runs early, by N/4 = 512 frames an octave up, and its last frames mix the take's last grains with grains that read the silence after it. Plain OLA's level is the interference of its grains, which can cancel a held tone deep where they all overlap and less where fewer do, so at the end of a take the level can rise as well as fall: over the last 1024 frames against the output's middle, a held tone moves −0.9 to +2.6 dB at +1 semitone, −3.9 to +10.7 dB at +12 and −8.8 to +31.3 dB at +24, where the middle falls as far as 44.8 dB under the input and the end stays 7.8 to 14.5 dB under it (node scripts/ends.js: tones of 110 to 1000 Hz at 32 take lengths, 22.05 to 96 kHz; the lead, 508 to 516 frames an octave up at the three rates). Shifted down the output runs late, and the take's last sound plays on past its end, inside the audio manifest's declared tail.
Use when: Reference baseline, or the simplest possible shift for comparison.
Not for: Anything quality-sensitive.
granularNative granular pitch shift: fixed-size Hann grains laid at a constant output hop, each read from the source through an anti-aliased sinc stride read (no separate stretch+resample stage). Small grains make the per-grain splice audible as a signature grain-rate texture — that texture is the point, not a defect.
import { granular } from '@audio/shift' granular(audio, { ratio: 1.3 }) granular(audio, { ratio: 1.3, grainSize: 1024 })
| Param | Default | |
|---|---|---|
grainSize |
398 |
Grain length in samples |
Preserves grain-local timbre, characteristic textural quality.
Destroys pitch accuracy on complex tones, smooth envelopes — the 398-sample default is tuned so a chord's partials crumble audibly (~14% RMS loss) while a clean 440 Hz tone still tracks true; that crumble on chords is documented character, not a bug.
| f0 err | THD% | alias | attack corr | formant dist | phase coh | shift |
|---|---|---|---|---|---|---|
| 1.45 | 0.0 | 0.033 | 0.996 | 3.486 | 0.997 | 2.256 |
Worst shift score and worst formant dist among all 15 algorithms — small, uncorrelated grains smear the spectrum more than even paulstretch's random phase does. Raise grainSize toward 1024+ for a cleaner, less textural shift; the default favors character over transparency.
Use when: Creative/textural effects where grain character is desired.
Not for: Transparent pitch shifting.
samplePlayback-rate pitch shift. Hann-windowed sinc interpolation at a fractional read-head stepped by ratio per output sample. No time preservation — higher pitch = shorter clip.
import { sample } from '@audio/shift' sample(instrumentBuffer, { semitones: 7 }) sample(audio, { ratio: 2, sincRadius: 16 })
| Param | Default | |
|---|---|---|
sincRadius |
8 |
Windowed-sinc half-width (samples) |
Preserves waveform identity (literally the same audio, faster/slower), formants — everything scales together.
Destroys time: output duration = input_length / ratio, zero-padded to match API.
| f0 err | THD% | alias | attack corr | formant dist | phase coh | shift |
|---|---|---|---|---|---|---|
| 2.50 | 0.1 | 0.007 | 0.951 | 2.330 | 0.170 | 1.614 |
Phase coh 0.170 because the modulation rate itself shifts with the pitch (a 5 Hz tremolo becomes 7.5 Hz at ratio 1.5). This is correct behavior for a sampler — not an artifact.
Use when: Instrument one-shots, ROM-sample playback, tracker-style.
Not for: Time-preserving pitch shift.
hybridRuns phaseLock and wsola in parallel, crossfades sample-by-sample by spectral-flux transient confidence. Tonal regions resolve via the phase vocoder; attacks resolve via WSOLA similarity search, time-aligned against phaseLock before blending so the two engines' attacks land together.
import { hybrid } from '@audio/shift' hybrid(audio, { ratio: 1.5 }) hybrid(audio, { ratio: 1.5, hybridThreshold: 0.6 })
| Param | Default | |
|---|---|---|
hybridThreshold |
0.8 |
Spectral-flux z-score for full WSOLA blend |
Preserves tonal phase coherence + attack shape — simultaneously.
Destroys CPU budget (≈2×), formants.
| f0 err | THD% | alias | attack corr | formant dist | phase coh | shift |
|---|---|---|---|---|---|---|
| 0.00 | 0.0 | 0.000 | 0.984 | 1.423 | 0.999 | 1.824 |
Same phaseLock-derived numbers as phaseLock/transient on this non-percussive suite — the WSOLA blend never activates because nothing here crosses hybridThreshold. Worst shift score among the frequency-adjacent methods for the same reason: it's carrying wsola's parallel computation for a blend that stays at zero.
Use when: Mixed dynamic material where a single domain compromises the other.
Not for: Pure tonal (just use phaseLock) or pure percussive (just use transient).
lpcCanonical LPC source-filter pitch shift (residual-excited linear prediction, RELP lineage). Per frame: fit the vocal-tract all-pole filter A(z) by the autocorrelation method (Levinson-Durbin), inverse-filter the signal down to its spectrally-flat excitation residual, repitch that residual with the delay line splicer, then resynthesize through the unmodified 1/A(z) run continuously with block-switched coefficients. Over the take the synthesis filter's poles never move — the classical speech-processing complement to formant's cepstral envelope preservation, built on a different mechanism (an explicit source-filter model instead of a magnitude-envelope correction).
import { lpc } from '@audio/shift' lpc(audio, { ratio: 1.5 }) lpc(audio, { ratio: 1.5, order: 24, frameSize: 512 })
| Param | Default | |
|---|---|---|
order |
min(frameSize/16, round(2 + sr/1000)) |
AR filter order (pole count) |
frameSize |
1024 |
Analysis/synthesis frame length |
Preserves formant frequencies by construction — the filter that carries them is never touched, only its excitation is repitched.
Destroys pure tones by design: on a single sinusoid the AR envelope IS the partial, so the fit notches it out of the residual: what is left of it shifts, at the tone's level only where the tone is low or the shift small, and its onset rings at the original pitch, the family's defining tradeoff, not a bug. The level match keeps the take at the input's level, so what the body loses, the onset's ring carries, but it raises a render by 20 dB at most: a tone whose match asks more takes 20 dB and comes out under its input by the rest, 5 of 48 tones at ±5 semitones by up to 2.7 dB and 18 of 48 at ±12 by up to 4.7 dB (250 Hz to 4 kHz, 22.05 to 96 kHz). At 44.1 kHz a 110 Hz tone's body keeps its level within 1 dB at every shift to 12 semitones either way, 220 Hz to five semitones and at −12 (11 dB under at +12); 440 Hz lies up to 5 dB under to five semitones and at −12 (24 dB at +12), 880 Hz 8 to 13 dB under at five semitones and 23 to 38 dB at twelve, 1760 Hz 32 to 49 dB and 3520 Hz 47 to 52 dB at five and twelve (node scripts/ends.js lpc).
| f0 err | THD% | alias | attack corr | formant dist | phase coh | shift |
|---|---|---|---|---|---|---|
| 0.53 | 0.1 | 0.455 | 0.975 | 1.400 | 0.937 | 1.679 |
Alias 0.455 is the worst in the collection: the alias test's 14 kHz tone, shifted ×2, lands past Nyquist and is rightly gone from the residual; what is left is its onset ringing the fit's pole at 14 kHz, which the level match raises by its most, 20 dB, so the take comes out 6.8 dB under the input's level. Formant dist 1.400 is higher (worse) than formant's 0.760 on this synthetic vowel too, across every order from 8 to 64: the fitted envelope follows the fixture's individual harmonics as well as its three formants, where formant's deliberately-smoothed cepstral envelope doesn't. None of this is the intended material: real, less strictly periodic speech is what an unmodified synthesis filter is for.
lpc renders a call as one take, whatever it holds: no level is silence, and nothing parts it. Each frame of a quarter frameSize takes the fit of its forward window, the fit window that starts with it, unless another window that holds it whitens its own samples by 0.5 dB more. A held tone's frames gain at most 0.31 dB from another window and a held reed-like note's nothing, so they keep their forward windows and their fit does not step from window to window; a held vowel's frames gain up to 2.01 dB, and 30 % of them take another window; where a take is cut into quieter sound, the frames before the cut, whose forward windows cross it, gain 13.5 dB at the median from a window of the take and take that one, and those after it take fits of what follows; the voice's frames gain 0.65 dB at the median (node scripts/ends.js margin). Where the past predicts what is no longer there, as at a cut, the inverse filter's memory is cleared and the frame's samples on either side take fits of their own; the filter rings on over the cut, as at a stop. A memory is cleared only where that saves the frame at least the share of its residual that the order samples it changes hold, so a held note, which its past predicts, clears none inside it: a reed-like note with steep edges, at 22.05 to 96 kHz and ±5 and ±12 semitones, keeps the loudest 2 ms of its second difference within 6.5 dB of its median, nothing clicking, and the energy between its harmonics 26.1 dB under that on them at least (node scripts/ends.js held). Shifted up, the delay line plays what follows a fall of the filters' gain, a cut or a vowel's end, up to 2560 frames early through the filters before it, which would lift it by their gain; the residual's scale is the filters' gain under its peak, the peak falling back 1 dB in 2560 frames, so what is read across a fall plays at its own level, and the scale, never under the gain's least, holds a long call's level: the voice cut loud and 0.3 s of room noise, written 26 times over, each copy within 1.18 dB of the first at 22.05 kHz, 0.60 dB at 44.1 kHz and 0.36 dB at 96 kHz (node scripts/ends.js long). The last part before a cut is the exception to the mean: every fit window that holds it holds the cut's step, so it whitens worse than the parts before it and its filters lift less, and it takes its own gain where that lies under the mean; what the delay line reads of it early then plays through the filters before it at its own level. A frame of exact zeros has nothing to fit: the last fit goes on, its poles drawn inward 60 Hz a frame from the last sound on, and its ring ends inside the audio manifest's declared tail, so a stop renders the same wherever it falls, at the call's end, mid-call or in a channel that ends early, up to the channel's one gain. Each channel's level is matched once a call: one gain a channel, its energy in over its energy out over the call's frames up to the last sound of any channel, so the level cannot follow the sound and pump, and every channel comes out at its own input's level, so the channels keep their balance: the voice beside a pluck train or a rock beat 20 dB under it, at 22.05 to 96 kHz and ±5 and ±12 semitones, each channel within 4.2e-8 dB of its own input's level, float32's rounding (node scripts/ends.js match). On a steady vowel the energy between the harmonics stays 27.8 to 48.2 dB under the energy on them (the same script). Over the 1024 frames after a stop that ends the call, re the 1024 before it, the ring holds −81.6 to −1.3 dB (node scripts/ends.js lpc).
So a take cut loud keeps its level whatever follows the cut: into exact zeros, Gaussian noise 20 to 100 dB under it or a 16-bit file's dither, its peak 0 to −60 dBFS, at ±5 and ±12 semitones, its first 0.4 s comes out +0.2 to +1.2 dB and its last 0.1 s −1.6 to −0.3 dB re its input at 44.1 kHz, −0.1 to +1.3 and −1.7 to 0.0 dB at 96 kHz, and nothing before the cut sounds over the take: over its last 0.1 s the loudest 64 frames lie at most 1.2 dB over the input's loudest there at 44.1 kHz, 1.6 dB at 22.05 kHz and 5.0 dB at 96 kHz (−60 dBFS, −12 st). A take faded into zeros comes out 0.0 dB re its input, and a 220 Hz tone hovering at 2.0e-5 to 4.5e-5 alone at its own level, −0.0 to 0.0 dB (node scripts/ends.js drop: the voice, audio-lena; the take cut loud at 22.05, 44.1 and 96 kHz, the rest at 44.1 kHz).
What lpc cannot do: keep each sound of a channel at its own level. A channel's one gain is the whole call's: of two notes, the second 12 dB down, with nothing, 300, 1023 or 1025 frames or 0.2 s of zeros, dither or noise 60 dB under between them, the first, which sets the gain, comes out −0.0 to +0.1 dB re its input, and the second, past the 2560 frames over which the delay line plays the first late, −3.8 to +0.4 dB at 44.1 kHz (−3.7 to +0.4 dB over all of it) and −7.3 to +0.8 dB at 96 kHz, its lowest at −12 semitones; a gap of 1025 frames moves it 0.11 dB at most from one of 1023 at 44.1 kHz, 0.32 dB at 96 kHz. The 220 Hz tone hovering low after a loud voice takes the voice's gain, −4.6 to −1.0 dB re its input (node scripts/ends.js drop). Nor can it render a take apart from what follows it within the delay line's reach. The line reads the residual across a cut, up to 2560 frames ahead shifted up and 512 shifted down, its splices 256 frames further, and splices on what it reads, so over the take's last frames its render into noise 60 and 100 dB under departs from its render into zeros: at 44.1 kHz by up to −3.0 dB re the take's RMS shifted up, over 60 dB under it from 1378 frames before the cut, and by −134.4 dB at most shifted down; short of the cut's reach (6921 frames) by −139.4 and −134.4 dB at most, its one gain apart (96 kHz: +4.3 dB from 1664 frames up, −34.8 dB from 128 frames down). At 22.05 kHz, where those frames are a fifth of the take, its first 0.4 s comes out +1.3 to +2.8 dB and its last 0.1 s −9.3 to −2.0 dB re its input, and into noise it departs by up to +2.7 dB re the take's RMS from 1361 frames before the cut shifted up, −44.1 dB from 209 frames shifted down (node scripts/ends.js drop). A sound after the take moves it within that reach: a click 2000 frames on by −11.7 dB re its RMS, read early at its own level, and dither 100 dB under it by up to 3.8 dB; short of that reach (6921 to 6929 frames) the take and its ring are written as at the call's end up to its one gain, in each of 32 renders at a stop mid-call 0.5 s before more sound, into dither 100 dB under, with a click 2000 frames on, and in a channel ending 0.2 s early, all of it (node scripts/ends.js lpc: a sung voice and a 220 Hz tone at 22.05 to 96 kHz, ±5 and ±12 semitones). Nor can it keep a sound gated faster than its scale returns quiet in its gaps: the delay line reads the next burst early through the filters, and the scale that holds a cut take's head lets it through. A vowel gated at 10 and 4 Hz over room noise 60 dB under it keeps its level, −0.4 to 0.0 dB re its input, but the room noise in the gaps comes out 39.6 to 45.0 dB over its own level (node scripts/ends.js long: 44.1 kHz, +5 and +12 semitones); room tone 60 dB under four vowel phrases comes out −0.7 to +4.3 dB re its input in the pauses between them, but shifted up at 22.05 kHz, where the 2560 frames the delay line reads early span a quarter of each pause, its loudest 20 ms reach 13.4 dB over its level there, the input's own 2.3 dB (node scripts/ends.js match). Nor can it start a take mid-sound without a click: over the first 10 ms of a take that starts loud, the output's peak reaches 17.9 dB over the input's (the voice from 2 s at 96 kHz, −12 semitones), 2.4 dB at the median and over 6 dB in 14 of 48 renders (node scripts/ends.js head: the voice from 2 s and the voice cut loud, 22.05 to 96 kHz, ±1, ±5 and ±12 semitones).
Every fit is bandwidth-expanded, a_k·0.994^k (the weighting factor of FED-STD-1016 § 3.7.2), so no pole sits on the unit circle and a pure tone renders bounded: over the take's middle at most 1.06 times its peak at ±5 semitones and 0.98 times at ±12, over its first 4096 frames, where the onset rings the fit's pole, at most 9.82 and 13.66 times (node scripts/ends.js lpc: 250 Hz to 4 kHz, 22.05 to 96 kHz). A tone moved past half the rate, which the shift leaves silent, stays 85.9 dB under its input over its middle at least, but its onset rings at the tone's own pitch, and its match asks more than 20 dB to bring that ring to the input's energy: it takes 20, the take comes out 2.5 to 7.8 dB under its input, and the ring's peak reaches 17.7 dB over the input's (node scripts/ends.js match). After 0.25 s of silence a tone's match asks more: the click, which can land up to 20 ms before the tone, reaches 9.38 times the tone's peak at ±5 semitones and 6.72 times at ±12, and 18 and 36 of the 48 tones come out under their input, by up to 18.7 and 28.8 dB (node scripts/ends.js lpc); a tone moved past half the rate comes out 25.0 to 29.5 dB under its input there, its peak 12.8 dB over the input's (node scripts/ends.js match).
Every level lpc compares is the call's own, a ratio of two energies or gains, none an absolute level, so a call times a factor renders as its render times that factor. A power of two does so bit for bit but where a ring's far tail falls into float32's subnormals, under 2^-126, and rounds otherwise: no sample over 2^-118.7 differs, none within 569.7 dB of the render's peak. Any other factor does so within its rounding, on the voice to −94.3 dB re the peak; on a pure tone a rounding can move the delay line's splices, to −13.8 dB (node scripts/ends.js scale: 675 channel renders, the voice and two tones at 22.05 to 96 kHz, alone and beside a channel 30 dB down, 2^-20 to 2^4).
Use when: Speech/vocals where the formants must not move with pitch, and the material isn't a bare sustained tone.
Not for: Pure tones, synth pads, or anything where the "partial" and the "envelope" are the same thing.
vocoder, phaseLock, transient, formant, paulstretch, sms, hpss, sample, delay, and lpc accept a time-varying ratio — a function (t) => ratio or a Float32Array (paired with ratioDuration in seconds, defaulting to the array's own length at sampleRate). ola, wsola, psola, granular, and hybrid apply a single global ratio and reject a variable one.
// Vibrato: ±10% at 5 Hz let vibrato = phaseLock(audio, { ratio: (t) => 1 + 0.1 * Math.sin(2 * Math.PI * 5 * t), sampleRate: 44100, })
Combine with a pitch detector: detect per-frame f0, snap to target scale, pass as ratio function. Use formant for natural voice, phaseLock for hard-tune effect, sms for harmonic instruments, lpc where formant fidelity matters most.
import { yin } from '@audio/pitch' import { formant } from '@audio/shift' let hop = 512, sr = 44100 let pitchFrames = [] for (let i = 0; i + 2048 <= audio.length; i += hop) { let r = yin(audio.subarray(i, i + 2048), { fs: sr }) pitchFrames.push(r ? { freq: r.freq, clarity: r.clarity } : null) } let scale = [261.63, 293.66, 329.63, 349.23, 392.00, 440.00, 493.88] let snap = (f) => scale.reduce((a, b) => Math.abs(Math.log2(b / f)) < Math.abs(Math.log2(a / f)) ? b : a ) let corrected = formant(audio, { ratio: (t) => { let p = pitchFrames[Math.min(Math.round(t * sr / hop), pitchFrames.length - 1)] return (!p || p.clarity < 0.5) ? 1 : snap(p.freq) / p.freq }, sampleRate: sr, })
npm test # correctness npm run quality # measured metrics npm run bench # performance
| Algorithm | f0 err | THD% | alias | stream corr | cent err | onset err | attack corr | formant dist | phase coh | shift |
|---|---|---|---|---|---|---|---|---|---|---|
hpss |
0.00 | 0.0 | 0.053 | 1.000 | 0.013 | 0.000 | 0.998 | 1.207 | 0.928 | 1.487 |
vocoder |
0.00 | 0.0 | 0.000 | 1.000 | 0.009 | 0.000 | 0.981 | 1.158 | 0.928 | 1.553 |
formant |
0.00 | 0.0 | 0.000 | 1.000 | 0.058 | 0.000 | 0.987 | 0.765 | 1.000 | 1.573 |
delay |
1.10 | 0.1 | 0.028 | 1.000 | 0.004 | 0.000 | 0.995 | 2.445 | 0.940 | 1.610 |
sample |
2.50 | 0.1 | 0.007 | 1.000 | 0.004 | 0.000 | 0.951 | 2.330 | 0.170 | 1.614 |
wsola |
1.67 | 0.1 | 0.005 | 1.000 | 0.003 | 0.000 | 0.995 | 2.358 | 0.864 | 1.674 |
lpc |
0.53 | 0.1 | 0.455 | 1.000 | 0.195 | 0.000 | 0.975 | 1.400 | 0.937 | 1.679 |
sms |
0.00 | 0.0 | 0.002 | 1.000 | 0.002 | 0.000 | 0.963 | 1.845 | 0.929 | 1.701 |
phaseLock |
0.00 | 0.0 | 0.000 | 1.000 | 0.008 | 0.000 | 0.984 | 1.423 | 0.999 | 1.755 |
pitchShift |
0.00 | 0.0 | 0.000 | 1.000 | 0.008 | 0.000 | 0.984 | 1.423 | 0.999 | 1.755 |
transient |
0.00 | 0.0 | 0.000 | 1.000 | 0.008 | 0.000 | 0.984 | 1.423 | 0.999 | 1.755 |
psola |
0.66 | 0.2 | 0.005 | 1.000 | 0.003 | 0.000 | 0.941 | 2.336 | 0.998 | 1.766 |
hybrid |
0.00 | 0.0 | 0.000 | 1.000 | 0.000 | 0.000 | 0.984 | 1.423 | 0.999 | 1.824 |
ola |
38.33 | 0.2 | 0.004 | 1.000 | 0.042 | 0.388 | 0.980 | 2.342 | 0.995 | 2.025 |
paulstretch |
0.00 | 0.2 | 0.230 | 1.000 | 0.043 | 0.000 | 0.935 | 7.371 | 0.518 | 2.221 |
granular |
1.45 | 0.0 | 0.033 | 1.000 | 0.040 | 0.452 | 0.996 | 3.486 | 0.997 | 2.256 |
ola/wsola/psola onlyhybridEvery other algorithm (granular, sample, delay, lpc) owns its primitives directly — no FFT, no external stretcher.
Previously held by mikolalysenko/pitch-shift (2013, v0.0.0) — a single WSOLA/TD-PSOLA implementation. Available here as wsola or psola with batch, streaming, and multi-channel support.
// v0.0.0 (old) var shifter = require('@audio/shift')(onData, t => ratio, { frameSize: 2048 }) shifter.feed(float32Array) // v1 (this package) import { wsola } from '@audio/shift' let write = wsola({ ratio }) let out = write(float32Array) let tail = write() // flush
audiojs/shift is a public repo on GitHub by audiojs. Pitch shift algorithms.
It declares the MIT license on GitHub.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2026-11-21. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
High-level audio manipulations: loading, playback, analysis, editing, processing. 140+ plugins.
This page is also available as structured data, with the same sources and dates.
/api/v1/resources/gh/audiojs/shiftTake My Repo has not tested this on your machine. Requirements come from the project's own documentation.