LabDAW

Wave shaper

A wave shaper synth device: a waveform, a drive, a tone, a detune, a mix and a volume, a panel with a pad that plays it, a Web Audio engine with noteOn and noteOff, and tools for agents.

Audio UI

Two detuned oscillators, a distortion mixed in with the clean sound, and a low-pass filter. Press the pad: the pitch goes across and the resonance goes up. It is a device: a state, a panel, an engine and tools, each its own file.

Installation

pnpm dlx shadcn@latest add @audio-ui/wave-shaper

It installs the device's state, its engine and its panel to components/audio-ui/devices/wave-shaper/. The demo above, which wires them to a loop, is @audio-ui/block-wave-shaper.

Controls

Controls · 6

Panel

The panel has a pad that plays the synth: the pitch goes across and the resonance goes up. waveShaperPitch(position) and waveShaperResonance(position) turn a position from 0 to 1 into a note. With activeNotes, the notes held now, such as on a MIDI keyboard, take the pad's point to the pitch of the last one, and waveShaperPosition(frequency) is where a pitch sits.

import { WaveShaperPanel } from "@/components/audio-ui/devices/wave-shaper/panel";
import { waveShaperDevice } from "@/components/audio-ui/devices/wave-shaper/device";

const [state, setState] = useState(() => waveShaperDevice.defaults());

<WaveShaperPanel onValueChange={setState} value={state} />;

Engine

Create it, connect it and update it as for any device: see The engine.

engine.noteOn(note); // starts a note now, or glides the one being held
engine.noteOff(); // lets it go

// Scheduled ahead on the audio clock, by a host that plays notes from a song:
engine.noteOn({ ...note, velocity: 0.8 }, { at: time, id: "c4" });
engine.noteOff({ at: time + length, id: "c4" });

One voice at a time, as the pocket synth. The distortion curve is a table of 44,100 points, rebuilt only when the drive changes. The shaper oversamples 4x, which delays its path by 4 ms, and the clean path waits as long so the mix does not comb.

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