BreakbeatLab: slicing, beat anchors and time stretching
Investigating deterministic rhythmic variation and transient-preserving duration changes in a two-deck instrument.
Technical research · edition 2 · reviewed 2026-10-24

Prismal Labs native editor capture, illustrating the corresponding software project. View full-size image
What we found
The breakbeat work showed that matching a loop's start times is not enough to preserve its groove when tempo changes. A sequenced chop can expire early, stretch its attack or duplicate a transient if source traversal and local playback are not separated. Stereo channels can also drift if their alignment searches choose different offsets.
We implemented a bounded stereo-linked waveform-similarity method with prepared attack anchors. Attacks retain a short natural-rate neighborhood; the body between attacks absorbs the duration change. This is a practical design for rhythmic material, with explicit failure and quality boundaries.
Protect the attack; stretch the body
source/stretch.h implements stereo-linked waveform-similarity overlap-add.
Source traversal follows elapsed musical beats; the playback increment within
each grain depends on sample rate and intentional pitch only. At each overlap,
one bounded coarse/fine normalized correlation search aligns both channels to
the same source position. Complementary smoothstep windows avoid gain holes.
Sample::detectAttacks() prepares independent attack anchors during WAV loading,
generation or PCM-state reconstruction. Every anchor begins a new stretch region.
Up to twelve milliseconds of its attack are copied at the normal playback rate;
the remaining body absorbs the duration change. Correlation windows stay within
that body's source region, so they cannot copy another attack into the overlap.
Small regions adapt their window size. Source lookahead uses already loaded PCM,
so the method adds no MIDI-onset or reported host latency.
Voices use fixed scalar state and stack correlation arrays. Processing does not allocate, lock, decode audio or build analysis tables. The existing 32-voice pool, asset pin/candidate ownership and anti-alias sample pyramid remain in use. Active sequenced voices expire in beats rather than their initial frame count. Changing tempo therefore updates their remaining duration as well as the clock.
The algorithm is authored for rhythmic/percussive material. Very large duration changes can expose repeated sustain texture; the tested duration range is one-half to four times the source duration. Source silence remains musical silence. Sharp attacks cannot be kept arbitrarily long when a chop/ratchet is shorter than the attack itself.
Evidence: Drums/BreakbeatLab/TIME-STRETCHING.md.
The mathematics of independent tempo and pitch
Musical traversal follows accumulated beats, while local grain playback uses sourceRate/hostRate * 2^(pitchSemitones/12). Changing host tempo alters the beat-to-source traversal and remaining beat duration, not that local increment. This separation is why active sequenced chops can follow a new tempo without a varispeed pitch jump.
A waveform-similarity search compares an outgoing window a with a candidate incoming window b_tau using normalized correlation: rho(tau) = dot(a,b_tau) / sqrt(dot(a,a)*dot(b_tau,b_tau)), with an explicit small-energy policy. The implementation bounds its coarse/fine search and selects one alignment for both channels. Complementary crossfade weights satisfy w0+w1=1; a smoothstep transition avoids a discontinuous gain handover.
The attack-region boundary restricts candidate windows. Without that restriction, an apparently strong correlation can copy the next drum attack into the current overlap, producing an extra hit. A stereo-linked search similarly avoids changing the source's interchannel timing by optimizing left and right independently.
Independent test signals and acceptance
BreakbeatLabStretch complements the engine/processor/editor gates. It checks:
- Independently generated 50, 110, 440 and 1,760 Hz tones at four source rates, stretched to five durations. Frequency error stays below max(0.2 Hz, 0.25%).
- Sustained-body coverage, finite bounds and a known stereo relationship.
- Three known drum attacks: original 96-frame shapes, scheduled onset positions and exactly three attacks at each tested duration, without doubling or skipping.
- Active-chop tempo changes through 120, 240 and 80 BPM, pitch and coverage.
- Allocation-free stretching and valid, repeatable, protected randomization.
The native editor test presses the actual Randomize button twice, checks locks
and neighboring scenes, then presses Undo and restores the original layout.
Existing block-partition and state tests remain required. Audio fixtures are
written under <build>/breakbeat-stretch-fixtures/; they contain independent
test tones/attacks rather than private prep audio. Actual Ableton tempo edits,
Randomize/Undo, project recall and output exports are a separate host gate.
tools/inspect-stretch.py inspects native fixture pitch, attacks and coverage.
tools/inspect-live-stretch.py independently checks the owned 90/174 BPM exports,
protected Randomize cells, byte-identical Undo patches, saved host PCM/layout
and identical stopped/playing Undo exports. Unexpected host observations stay
in a separate diagnostic section of the current receipt.
Product identities, 44 saved parameters and state version 1 are unchanged.
Existing projects load their samples/scenes through the same schema and use the
new sequenced stretch behavior. The current handoff (HANDOFF.md, retained research) and
validation receipt (VALIDATION.json, retained research) identify the accepted installed build.
Evidence: Drums/BreakbeatLab/TIME-STRETCHING.md.
Deterministic variation is part of timing
The Groove + Chops toolbar adds Randomize beside Remix. Randomize rerolls every editable cell in both lanes of the current scene using the selected style. Locks always survive; Protect downbeats preserves beat anchors. Other scenes, sample audio, cuts, mixer/effects settings and the temporal Variation seed are retained. The saved scene contributes to the random seed, so another press makes a fresh variation after recall. Undo edit restores the complete previous scene. Remix continues to use the Variation amount for partial edits.
Evidence: Drums/BreakbeatLab/TIME-STRETCHING.md.
Applying the findings
Validate with independent tones and known isolated attacks before judging a complex loop. Count attacks, measure their onset locations and compare their original shapes; a pitch-only score can miss a duplicated kick. Change tempo while a chop is active and verify both its pitch and remaining coverage.
Seed rhythmic decisions from musical state rather than callback count. Render the same scene with different host block partitions and compare the result. Preserve locked cells and beat anchors during randomization, and test Undo on the complete scene state. Those techniques transfer to sequencers and generative arrangements beyond breakbeats.
Limits and open questions
The tested duration range is one-half to four times the source duration. Large stretches can reveal repeated sustain texture, and an attack cannot be preserved indefinitely inside a shorter ratchet. Correct source beat length remains part of the input contract. Direct MIDI chops retain natural playback behavior, while sequenced chops use scheduled beat durations.
Primary references
Research provenance
The methods and results above are drawn from these retained research records. Dates and product versions inside the article identify the scope of each experiment; publication review does not mean the hardware or numerical tests were rerun.
Drums/BreakbeatLab/source/stretch.h— SHA-256093637cd4aff08fbfe304706e5e63c4b1a0854c646175ff1561e5ef08edf55c8Drums/BreakbeatLab/TIME-STRETCHING.md— SHA-256c101e86296e964ba6c70dc37601f3d0ad54392baaafd4c749c8c6cf98662acea
