Sampling — Time Stretching & Pitch Shifting
Our sampler exposed a limitation: when we change the speed of a buffer, pitch and duration change together. Time-stretching techniques try to break that relationship.
1. Three different operations
Change read speed.
Pitch and duration move together.
Change duration while trying to preserve pitch.
Change pitch while trying to preserve duration.
That coupling is exactly what we heard when key-spanning the C2 sample. To separate time from pitch we need to do more than simply move one read head faster or slower.
2. Start with chunks
Imagine cutting the recording into short overlapping windows. We can reposition those pieces in time, repeat them, omit them, and blend their edges.
The waveform is illustrative. The blocks below show the basic idea: output windows can be placed closer together or farther apart than their source positions.
3. Hear a simple browser time stretcher
This is deliberately a teaching algorithm, not Ableton Warp. Load audio, choose a stretch amount and window size, then render it using short windowed grains with overlap/add.
4. Why overlap and windows?
If we simply chop audio and butt the pieces together, discontinuities at the joins can produce clicks. A window fades each piece in and out, and overlapping neighbouring pieces lets them crossfade.
5. Families of time-stretching algorithms
Window short chunks and overlap them at new positions. Simple and useful for understanding the principle.
Search around expected positions for waveform sections that align well before overlapping them. This can reduce obvious discontinuities.
Analyse short windows with the FFT/STFT, manipulate their progression through time, then reconstruct the signal.
Work with many very short grains whose position, rate, envelope and overlap can be controlled independently.
Commercial time-stretching systems may combine or extend these ideas with transient detection, formant handling, source-specific processing and other techniques.
6. Pitch shifting from time stretching
One conceptual route to independent pitch shifting is surprisingly neat:
For example, resampling upward by an octave makes the sound twice as fast and half as long. If a time stretcher then expands that result back to the original duration, the pitch change can remain while much of the duration change is removed.
7. From correction to synthesis
Make the chunks smaller and smaller: 100 ms → 50 ms → 20 ms → 10 ms. At some point we stop thinking only about repairing or stretching a recording and start treating the tiny fragments themselves as musical material.