This document describes how to build a simple drum machine using React and the Web Audio API. It discusses:
1. Initializing state in React to track the pattern, current step, and playback status.
2. Rendering the state values.
3. Using the Web Audio API for precise audio timing by initializing an AudioContext and WAAClock on mount.
4. Implementing play/stop logic by starting/stopping the clock and scheduling the tick callback.
5. Advancing the step and triggering sounds on each tick via the deadline parameter.
13. setInterval AudioContext
• Inaccurate
• Gets locked up by other JS
on the main thread
• Extremely accurate
• Runs on dedicated audio
thread
• Can only schedule audio-
related events ahead of
time
Timing Options