An open API service indexing awesome lists of open source software.

https://github.com/biggyspender/web-audio-drum-machine

A modern, interactive drum machine and step sequencer built with React and TypeScript, showcasing real-time audio synthesis and effects using the Web Audio API.
https://github.com/biggyspender/web-audio-drum-machine

audio-context audio-worklet browser-audio drum-machine experimental music react sequencer step-sequencer synthesizer typescript web-audio web-audio-api

Last synced: 3 months ago
JSON representation

A modern, interactive drum machine and step sequencer built with React and TypeScript, showcasing real-time audio synthesis and effects using the Web Audio API.

Awesome Lists containing this project

README

          

# ๐Ÿฅ Drum Machine (Web Audio API Experiment)

[๐Ÿš€ **Live Demo**](https://biggyspender.github.io/web-audio-drum-machine/)

This project is an experimental drum machine and step sequencer built with React and TypeScript, designed to explore the capabilities of the Web Audio API's `AudioContext` for real-time audio synthesis, sequencing, and effects in the browser.

## โœจ Features

- ๐ŸŽ›๏ธ **Step Sequencer UI**: 16-step grid for programming drum patterns interactively.
- ๐Ÿฅ **Sample-based Drum Tracks**: Built-in drum sounds (kick, snare, hat, clap) loaded as audio samples.
- โฑ๏ธ **Real-time Playback**: Accurate timing and scheduling using a custom sequencer clock implemented with AudioWorklet and Comlink for low-latency, sample-accurate step events.
- ๐ŸŽš๏ธ **Adjustable Parameters**:
- โฉ **BPM**: Change tempo in real time.
- ๐ŸŽท **Swing**: Add groove by shifting off-beat steps.
- ๐Ÿงช *(Experimental)*: Humanization controls for velocity and timing (commented in code).
- ๐ŸŽง **Audio Effects**: Built-in echo and convolution reverb (with impulse response sample) applied to the output chain.
- ๐Ÿ”„ **Persistent Audio Pipeline**: Audio nodes and effects are managed efficiently for smooth parameter changes and low CPU usage.
- โŒจ๏ธ **Keyboard Control**: Spacebar toggles playback (unless a text input is focused).
- ๐Ÿ–ฅ๏ธ **Modern UI**: Responsive, styled with CSS modules for a vintage drum machine look.

## ๐Ÿ› ๏ธ Technical Highlights

- ๐ŸŽต **Web Audio API**: Uses `AudioContext`, `AudioBufferSourceNode`, and custom AudioWorklet processors for precise timing.
- ๐Ÿ”— **Comlink**: Bridges main thread and AudioWorklet for event-driven step callbacks.
- โš›๏ธ **React**: Functional components and hooks for UI and state management.
- ๐Ÿฆบ **TypeScript**: Strongly typed audio and sequencer logic.
- โšก **Vite**: Fast development and build tooling.
- ๐Ÿงช **Storybook & Vitest**: For component development and testing.

## ๐Ÿš€ Getting Started

### ๐Ÿ“ฆ Prerequisites
- ๐ŸŸข Node.js (18+ recommended)
- ๐Ÿ“ฆ pnpm (or npm/yarn)

### โ–ถ๏ธ Install & Run
```bash
pnpm install
pnpm start
```
Then open [http://localhost:5005](http://localhost:5005) in your browser.

### ๐ŸŽน Usage
- ๐Ÿ–ฑ๏ธ Click steps in the grid to activate/deactivate drum hits.
- ๐ŸŽš๏ธ Adjust BPM and swing with the knobs.
- โ–ถ๏ธ Press the play button or use the spacebar to start/stop playback.
- โน๏ธ Use the stop button to reset to the beginning.

## ๐Ÿ—‚๏ธ Project Structure
- `src/DrumMachine.tsx` โ€” Main UI and sequencer logic
- `src/audio/` โ€” Audio engine, effects, and sequencing
- `src/components/` โ€” UI components (knobs, buttons, sequencer grid)
- `src/audio/getSequencerClock/` โ€” Custom AudioWorklet-based sequencer clock

## ๐Ÿง‘โ€๐Ÿ’ป Code Conventions & Experiments
- ๐Ÿญ Factory functions over classes for audio pipeline management
- ๐Ÿ“ก Event-driven state via custom event bus
- ๐Ÿ”„ Real-time parameter updates (BPM, swing) without audio glitches
- ๐Ÿงฉ Modular, testable code with strong typing

## ๐Ÿ™ Credits
- ๐Ÿฅ Drum samples and impulse responses are included in `src/audio/assets/audio/`.
- ๐Ÿ› ๏ธ Built with [React](https://react.dev/), [Vite](https://vitejs.dev/), and [Comlink](https://github.com/GoogleChromeLabs/comlink).

## ๐Ÿ“„ License

This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.

---

For more details, see the code and comments throughout the `src/audio/` and `src/DrumMachine.tsx` files.