Learn SONIC-PI with Real Code Examples
Updated Nov 26, 2025
Explain
Sonic Pi provides a Ruby-based DSL for musical composition and live performance.
Users can program beats, synths, loops, and samples using code.
It encourages learning programming through music and creativity.
Supports real-time audio output with low latency.
Can be used for both educational and professional musical applications.
Core Features
`play` - plays a note or chord
`sample` - plays audio samples
`sleep` - defines duration between notes
`live_loop` - loops music in real-time
Threading and concurrency for layered compositions
Basic Concepts Overview
Note values (e.g., `:C4`, `:E3`) for pitch
Synths (e.g., `:beep`, `:prophet`) for sound types
`sleep` to define note duration
`live_loop` for repeating sections
Effects (FX) and samples to modify or layer sound
Project Structure
Single `.spi` script file per composition
Optional multiple buffers for organization
Assets folder for custom samples
No complex file system required
Entire composition often contained in one live code session
Building Workflow
Write code in Sonic Pi editor
Use `play` or `sample` commands to generate sound
Define loops with `live_loop` for repetition
Add FX and timing adjustments
Iterate and modify in real-time while listening
Difficulty Use Cases
Beginner: play simple notes and loops
Intermediate: combine loops and synths
Advanced: use FX, concurrency, and samples creatively
Expert: live coding performance and algorithmic composition
Architect: integrate Sonic Pi with sensors or external MIDI controllers
Comparisons
Sonic Pi vs Pure Data -> Pure Data: visual programming, Sonic Pi: live coding text
Sonic Pi vs SuperCollider -> SuperCollider: advanced synthesis, Sonic Pi: beginner-friendly live coding
Sonic Pi vs Ableton Live -> Ableton: GUI DAW, Sonic Pi: code-based music
Sonic Pi vs ChucK -> ChucK: precise timing, Sonic Pi: easy learning and education
Sonic Pi vs TidalCycles -> TidalCycles: pattern-based, Sonic Pi: live coding with loops and synths
Versioning Timeline
2011 - Sonic Pi initial development by Sam Aaron
2012 - First public releases for education
2013 - Added advanced synths and FX
2015 - Integration with Raspberry Pi for schools
2020–2025 - Active updates and community growth
Glossary
Live coding - writing code to generate music in real-time
Synth - a software instrument generating sound
Sample - pre-recorded audio clip
FX - effects applied to sound
Loop - repeated section of music