Sonic Pi: samples, FX and generative texture
Learning objectives
- learner can load, slice, stretch and re-pitch samples for beat construction
- learner can wrap sounds in FX efficiently and build layered synth timbres
- learner can use deterministic randomness and probability to vary a pattern reproducibly
Capstone — one whole task that evidences the objectives
Produce a Sonic Pi track that beat-slices an external break, layers an additive/detuned synth pad through FX, and uses a fixed random seed with one_in probability so the 'random' variation is reproducible on replay.
Prerequisite modules
This module is where Sonic Pi stops being a toy sequencer and becomes a breaks machine: the whole task is a jungle/breakbeat-style track built from an external drum break you supply, re-chopped in code the way an MPC or beat-slicing sampler would do it, with a wide detuned pad floating over the top and variation that sounds random but replays identically — the property that lets you rehearse a “generative” section and still perform it live with confidence.
Start supported: load your break from disk (“Sonic Pi plays external audio files by passing a file path string to sample”) and lock it to the grid with beat_stretch so tempo changes stop breaking your loop. Then chop — first by manual slice math (“Chopping a sample into equal slices and playing them in random order creates beat-slicing effects”), then the idiomatic shortcut (“onset: pick… selects a random transient event”). Re-pitch slices with rpitch: once you understand why rate changes pitch and duration together. In parallel, build the pad from stacked detuned voices and wrap everything in FX the right way — loop inside the block, not the reverse, or your Raspberry Pi will choke. Finally, tame the randomness: one_in gives probabilistic hits, use_random_seed pins them down, and the determinism principle explains why that grip matters for performance.
Every required atom is load-bearing for the capstone: you cannot chop, stretch, layer, or reproduce the variation without them, and the drills (slice math, beat_stretch, with_fx placement, seeding) are the moves you’ll repeat until automatic. Supporting atoms widen the palette — sample-pack filtering, the slicer FX and its probabilistic gate, acid bass via :tb303, parameter slides, Euclidean spreads — plus historical context on why loop-thinking dominates this music. Reach for them after the capstone stands on its own.
Runnable examples
Generated from the context/ instrument corpus by concept (redistributable idioms only). Do not edit — regenerate with gen-module-examples.mjs.
sample-chop
s("breaks125:0").chop(8)
strudel-0020 · CC0
d1 $ chop 8 $ sound "break:0"
tidal-0019 · CC0
resonant-filter
SinOsc s => LPF f => dac; 400 => f.freq;
chuck-0002 · MIT
play :e2, cutoff: 90, res: 0.9, release: 0.3
sonicpi-0022 · CC0
euclidean-rhythm
s("bd(3,8)")
strudel-0004 · CC0
d1 $ sound "bd(3,8)"
tidal-0004 · CC0
detune-thickening
saw [110, 110.2] >> audio
punctual-0009 · CC0-1.0
d1 $ note "c2" # sound "supersaw" # detune 0.3
tidal-0039 · CC0
swing
s("hh*8").swingBy(1/3, 4)
strudel-0008 · CC0
d1 $ swingBy (1/3) 4 $ sound "hh*8"
tidal-0008 · CC0
step-probability
play :e4, release: 0.1 if one_in(3); sleep 0.25
sonicpi-0044 · CC0
SinOsc s => dac; while(true){ if(maybe) 440 => s.gain; else 0 => s.gain; 125::ms => now; }
chuck-0047 · MIT
additive-synthesis
{ Klang.ar(`[[100, 200, 300, 400], [0.4, 0.3, 0.2, 0.1]]) * 0.1 }.play
supercollider-0022 · CC0
reverse-playback
d1 $ sound "bd sn" # speed "-1"
tidal-0056 · CC0
seeded-randomness
use_random_seed 42; 8.times { play (scale :e3, :minor).choose; sleep 0.25 }
sonicpi-0051 · CC0
Atoms in this module
Required — these gate the capstone
Supporting — enrichment, not gating
Part of curricula
- Live Coder — zero to performing live-coded music — Generative Systems & the SuperCollider Stack optional