Instruments
Synthesizers and samplers
Instruments turn patterns into sound.
Synthesizers
Built-in waveform synthesizers:
[C4 E4 G4] |> saw // Sawtooth wave
[C4 E4 G4] |> sine // Sine wave
[C4 E4 G4] |> square // Square wave
[C4 E4 G4] |> triangle // Triangle wave
[C4 E4 G4] |> noise // White noise
[C4 E4 G4] |> supersaw // Detuned saw stackFM Synthesis
FM (Frequency Modulation) synthesis creates complex timbres by having one oscillator modulate another's frequency. Great for bells, electric pianos, and metallic sounds.
[C4 E4 G4] |> fm // Default FM sound
[C4 E4 G4] |> fm(ratio: 2.0, index: 5.0) // Custom ratio and depth
[C4 E4 G4] |> fm(ratio: 1.0, index: 3.0, feedback: 0.2) // With feedbackParameters:
| Parameter | Description | Default |
|---|---|---|
ratio | Modulator/carrier frequency ratio. Integer ratios (1, 2, 3) sound harmonic; non-integer ratios sound metallic/bell-like | 2.0 |
index | Modulation depth. Higher = more harmonics/brightness. 0 = pure sine | 5.0 |
feedback | Self-modulation amount (0.0-1.0). Adds grit and complexity | 0.0 |
Classic FM sounds:
// Electric piano (Rhodes-like)
play [C4 E4 G4] |> fm(ratio: 1.0, index: 3.0) |> adsr(0.01, 0.3, 0.4, 0.5)
// Bell/chime
play [C5 E5 G5] |> fm(ratio: 3.5, index: 6.0) |> adsr(0.01, 0.5, 0.2, 1.0)
// Aggressive bass
play [C2 _ C2 _] |> fm(ratio: 0.5, index: 8.0, feedback: 0.3)Samples
Load and play audio samples. Supported formats: WAV, FLAC, and MP3.
// Basic sample playback
let kick = sample("lib:drums/kick.wav")
// Melodic samples with root note
let glass = sample("lib:wine-glasses/glass1", root: C4)
// Use melodic sample with pattern — pitch-shifted from root
[C4 E4 G4] |> glassThe root: parameter tells Sanic Boom which note the original sample was recorded at. When you play different notes, the sample is pitch-shifted to match. This turns any single sample into a playable instrument.
Sample Libraries
Import sample packs from the sample library catalog:
import "github:SanicBoom/wine-glasses"
// Reference samples as lib:library-name/sample-name
let glass = sample("lib:wine-glasses/glass1", root: Eb4)
[Eb4 G4 Bb4] |> glass |> reverb(0.7)Browse all 150+ available libraries in the Sample Libraries page.
Reverse Playback
sample("lib:drums/snare.wav") |> reverseStart/End Positions
Play a portion of a sample using begin and end (0–1 normalized range):
// Play the second quarter of a break
sample("break.wav", begin: 0.25, end: 0.5)
// Pipe syntax
sample("break.wav") |> begin(0.25) |> end(0.5)
// Combine with other effects
sample("break.wav") |> begin(0.5) |> end(0.75) |> reverb(0.6)begin— Start position (0–1, default 0)end— End position (0–1, default 1)
Sample Slicing
Slice samples for breakbeat-style manipulation:
let break = sample("break.wav") |> slice(8)
// Access individual slices
[break[0] break[2] break[1] break[3]]Per-Note Instruments
Place instrument values directly inside patterns to trigger different samples per step — no need for separate lanes:
import "github:SanicBoom/808"
from "github:SanicBoom/808" import { kick, snare, hat }
play [kick _ snare hat]Each name resolves to a sample instrument, so the pattern plays kick on beat 1, snare on beat 3, and hat on beat 4. You can mix instruments freely:
from "github:SanicBoom/808" import { kick, snare, hat, clap }
play [kick hat snare hat | kick hat clap hat]Per-note instruments work with all note modifiers — probability, velocity, and duration weights:
play [kick snare?0.5 hat@0.6 hat:2]This is equivalent to writing separate stack()ed lanes but much more concise for drum patterns.
Pitch Modulation
Glide (Portamento)
Smooth pitch sliding between consecutive notes:
|> glide(0.1) // 100ms glide time
|> glide(50ms) // Using milliseconds
|> glide(time: 100ms) // Named parameterEssential for 303-style acid basslines:
let acid = [C2 C2 Eb2 C3]
|> saw
|> glide(80ms)
|> lowpass(800)Pitch Envelope
Modulate pitch over the note's duration:
|> pitchEnv(start: 2, end: 1, time: 0.05) // Kick drop
|> pitchEnv(start: 0.5, end: 4, time: 0.2) // Laser rise
|> pitchEnv(start: 1, end: 1.05, time: 0.1) // Subtle riseParameters:
| Parameter | Description |
|---|---|
start | Starting pitch multiplier (2 = octave up) |
end | Ending pitch multiplier (1 = normal) |
time | Time to reach end pitch in seconds |
Classic psytrance kick with pitch drop:
let kick = [C1]
|> sine
|> pitchEnv(start: 3, end: 1, time: 0.03)
|> adsr(0.001, 0.1, 0, 0.1)Combining with Effects
Chain instruments with effects:
[C4 E4 G4]
|> supersaw
|> lowpass(2000)
|> reverb(0.6)
|> delay(0.25)