Lesson 15 of 15
Drum Patterns
Step Sequencer
A step sequencer triggers sounds on a rhythmic grid. Each step is either ON (1) or OFF (0). At a given BPM, you convert the step grid into onset times.
Formula
Each step is a sixteenth note (1/4 of a beat):
stepDuration = 60 / (bpm × 4)
onsets = steps where pattern[i] === 1, at time i × stepDuration
Classic Drum Patterns
// 4-on-the-floor kick (16 steps):
kick: [1,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0]
// Snare on beats 2 and 4:
snare: [0,0,0,0, 1,0,0,0, 0,0,0,0, 1,0,0,0]
// Closed hi-hat every eighth note:
hihat: [1,0,1,0, 1,0,1,0, 1,0,1,0, 1,0,1,0]
Your Task
Implement patternOnsets(pattern, bpm) that returns an array of onset times (in seconds) for each active step.
Run your code to hear a basic beat: kick on 1 and 3, hi-hat on every eighth.
Web Audio API loading...
Loading...
Click "Run" to execute your code.