Choose an Audio Edit: Stretch, Shift or Retune
Editing DSP rewrites decoded audio samples. It changes the tempo, the pitch, one note, a time-frequency region or the character of a voice, instead of only measuring the sound. This page picks the edit, lists every call with its spelling in each binding, and holds the pitch and position units they share.
The calls themselves are on Change Tempo Without Changing Pitch and Pitch Correction, with Spectral Editing, Note Editing in Audio and Vocal Editing for the rest. If you only want to measure BPM, key, chords, or features, start with Getting Started instead.
If semitone, MIDI note number, or formant are unfamiliar, read Editing Basics first — this page assumes that vocabulary.
DSP vs editing
DSP means Digital Signal Processing: measuring or transforming audio as a signal. The editing DSP here does more than measure BPM or key; it rewrites the sound itself, changing pitch, duration, or vocal character.
Which Edit Do You Need?
| Goal | Use | Where |
|---|---|---|
| Make a clip longer or shorter without changing the note | timeStretch | Time-stretch |
| Move the whole clip up or down in pitch | pitchShift | Pitch shift |
| Nudge a vocal note toward a target note | pitchCorrectToMidi, pitchCorrectTimevarying | Pitch correction |
| Snap a vocal line or a whole recording to a scale or key | pitchCorrectTimevarying (scale mode), autoTune | Pitch correction |
| Hold or shorten one note region | noteStretch | Region selection |
| Attenuate or heal a time-frequency region | spectralEdit | Spectral editing |
| Change vocal character | voiceChange | Time-stretch and pitch-shift |
| Process live voice blocks with presets | RealtimeVoiceChanger | Realtime voice changer |
Units: notes, samples, and seconds
Every call below takes pitch as a MIDI note number or a semitone count, and positions as samples or seconds. These two tables are the conversions the examples rely on.
MIDI note numbers
A MIDI note number represents pitch as a semitone index. Each whole number is one semitone, and fractional values are allowed.
Two anchors are worth memorizing:
| Note | MIDI note number | Frequency |
|---|---|---|
| C4 (middle C) | 60 | about 261.63 Hz |
| A4 | 69 | 440 Hz |
Every octave adds 12. For example, C4 is 60, so C5 is 72.
For the full mapping table and the freq ↔ midi formula, see Editing Basics.
Samples and seconds
Every edit position can be given in samples or in seconds. Give one spelling per bound; supplying both is refused.
| Call | Samples | Seconds | Python (seconds) |
|---|---|---|---|
spectralEdit region | startSample / endSample | startSec / endSec | start_sec / end_sec |
noteStretch, noteMove | onsetSample / offsetSample; noteMove also targetOnsetSample | onsetSec / offsetSec; targetOnsetSec | onset_sec / offset_sec; target_onset_sec |
renderNotes, renderPercussiveEvents input records | onsetSample / offsetSample; edit timeOffsetSamples | onsetSec / offsetSec; timeOffsetSec | onset_sec / offset_sec; time_offset_sec |
Vocal setSourceSpan | sourceStartSample, sourceEndSample, destinationStartSample, destinationLengthSamples | the same names ending Sec | source_start_sec and the matching fields |
Vocal split | sourceSample | sourceSec | cut_source_sample / cut_source_sec |
Vocal render range | startSample / endSample | startSec / endSec | start_sec / end_sec keywords |
- Seconds are rounded to the nearest sample at the call's sample rate (a vocal session's own rate for the vocal rows).
- The seconds forms of the note and percussive rows belong to the input records (
NoteObjectInput,NoteEditInput,PercussiveEventInput,PercussiveEventEditInput). The recordsextractNotesandextractPercussiveEventsreturn carry samples only, and are accepted back as they are. - A negative position is refused:
RangeErroron WASM and Node,SonareValueErrorin Python. -1is not a "to the end" sentinel. Omit an end bound to take the input's edge (Python:None).
If a position comes from analysis, keep the sample value; it avoids a second rounding.
Functions
Parameters like f0Hz (a per-frame pitch contour), hopLength, and voiced are defined under Time-varying pitch correction below.
| Task | WASM / browser JavaScript | Python |
|---|---|---|
| Shift the whole signal without changing duration | pitchShift({ samples, sampleRate, pitchSemitones }) | pitch_shift(samples, sample_rate, pitch_semitones) |
| Time-stretch the whole signal without changing pitch | timeStretch({ samples, sampleRate, speedRatio }) | time_stretch(samples, sample_rate, speed_ratio) |
| Correct from one MIDI note to another | pitchCorrectToMidi({ samples, sampleRate, currentMidi, targetMidi }) | pitch_correct_to_midi(samples, sample_rate, current_midi, target_midi) |
| Follow a per-frame pitch contour toward a note | pitchCorrectTimevarying({ samples, sampleRate, f0Hz, hopLength, targetMode: 'midi', targetMidi }) | pitch_correct_timevarying(samples, sample_rate, f0_hz, hop_length, target_mode="midi", target_midi=...) |
| Snap a contour to a musical scale (automatic pitch correction) | pitchCorrectTimevarying({ samples, sampleRate, f0Hz, hopLength, targetMode: 'scale', ... }) | pitch_correct_timevarying(samples, sample_rate, f0_hz, hop_length, target_mode="scale", scale_root=..., ...) |
| Snap a whole recording to a detected or named key | autoTune({ samples, sampleRate, key, retuneAmount }) | auto_tune(samples, sample_rate, key, retune_amount=...) |
| Stretch only a note region | noteStretch({ samples, sampleRate, onsetSample, offsetSample, stretchRatio }) | note_stretch(samples, sample_rate, onset_sample, offset_sample, stretch_ratio) |
| Edit a time-frequency region | spectralEdit({ samples, sampleRate, ops, ...options }) | spectral_edit(samples, sample_rate, ops, ...) |
| Shift pitch and formants independently | voiceChange({ samples, sampleRate, pitchSemitones, formantFactor, formantMode? }) | voice_change(samples, sample_rate, pitch_semitones, formant_factor, formant_mode="relative") |
| Stateful realtime voice preset chain | RealtimeVoiceChanger | RealtimeVoiceChanger |
| One-shot realtime voice preset render | realtimeVoiceChangerRender({ channels, sampleRate, config? }) | realtime_voice_changer_render(samples, sample_rate, config=..., num_channels=1) |
Positional or request object
WASM and Node accept either positional arguments (samples, then sample rate, then an options object holding the edit amount) or a single request object with the same names; pick one style per file. realtimeVoiceChangerRender is request-only.
effects.modulation.ensemble and saturation.ampSim are creative inserts rather than functions on a raw buffer; load them on a strip as described on Effects Inserts.
Practical Notes
These APIs are intentionally lightweight editing tools, not a full non-destructive pitch editor. For transparent vocals, keep pitch correction intervals small and avoid extreme formant factors. For sound design, larger pitchSemitones and formantFactor moves are valid, but expect stronger artifacts.
Why big moves sound worse
These transforms work by analyzing the sound into short overlapping frames and re-spacing or re-pitching them. Small shifts stay close to the original frames and sound clean; large shifts force the engine to invent material that was never recorded, so you hear smearing, a "watery" or robotic quality, and a less natural voice. That is why the advice is to keep correction intervals small for transparent results.
Two resynthesis engines sit behind these calls, and they fail differently: pitchShift, pitchCorrectToMidi and voiceChange stretch and resample (formants move with the pitch), while the contour-following correctors and the vocal session repitch grain by grain (formants stay roughly in place). Two resynthesis engines lists which call uses which.