Lab

drum-synthesis

One-shot percussion synthesis (kick, snare, hihat) built from oscillators and noise bursts, each with its own tune and decay

pnpm dlx shadcn@latest add @audio-ui/drum-synthesis
import { triggerClick, triggerKick, triggerSnare, triggerHihat } from "@/lib/drum-synthesis";
Fileslib/drum-synthesis.ts
Depends onNothing
npmNothing
Used byarrangement-engine, block-drum-rack, demo-sound, drum-rack, pad-demo, sequencer, use-piano-roll-playback
ExportKindWhat it is
DrumOptionsinterfaceShapes one hit: tune in semitones from the voice's own pitch, decay in seconds.
triggerClickfunctionA metronome's click at time on the audio clock, higher on the first beat of a bar.
triggerKickfunctionSine oscillator with a fast pitch sweep (150Hz→40Hz) and exponential amplitude decay, a classic 808-style kick.
triggerSnarefunctionBand-passed noise burst for body plus a short triangle "click" for attack transient.
triggerHihatfunctionHigh-passed noise burst, a closed-hihat-style tick by default; a longer decay, such as 0.5 seconds, rings like an open hihat.

Usage

A kick, a snare and a hihat made from oscillators and noise, with no samples to load. Each starts at time and plays out on its own.

import { triggerHihat, triggerKick, triggerSnare } from "@/lib/drum-synthesis";

triggerKick(ctx, output, time);
triggerSnare(ctx, output, time, { tune: 2 });
triggerHihat(ctx, output, time, { decay: 0.5 }); // a longer decay rings open

tune shifts a hit in semitones from its own pitch and decay sets how long it lasts, in seconds. The Pad page plays a kit with them.

Built by Ouest Labs, the source code is available on GitHub.
RSS