useWebAudioMixer
Binds mixer state to a Web Audio graph, with ducking, monitor sends, a limited master and meters.
$ pnpm dlx shadcn@latest add @audiocn-solid/use-web-audio-mixerUsage
const mixer = useMixer({
channels: [{ id: "mic" }, { id: "music", monitor: true }],
});
const microphone = useMicrophone({ enabled: true });
const player = useAudioPlayer({ src: "/music.mp3" });
const graph = useWebAudioMixer(mixer, () => ({
inputs: { mic: microphone.stream, music: player.element },
ducking: { trigger: "mic", targets: ["music"] },
}));
<LevelMeter source={graph.meters.mic} />;
<LevelMeter source={graph.master.meter} />;The System Audio Mixer block is built on it.
The graph
Each channel runs through a gain, a ducking stage and a stereo panner. The panner feeds the master bus, and a monitor send feeds the speakers. The master bus runs through an optional peak limiter into a MediaStream for recording.
input → gain → duck → pan ─┬─→ master → limiter → output stream
└─→ monitor send → speakers
- Mute and solo are gain ramps, so they never click. Channels are built silent and fade in, so a muted channel is never heard while it is created.
- A duck holds for 200 ms after the trigger's last loud frame, then releases. It also releases when the trigger channel goes away mid-duck.
monitordecides whether a channel is heard in the speakers. It is off by default so a microphone does not feed back; turn it on for music and sounds.- A media element used as an input is taken over by the mixer while mounted, and routed back to the speakers afterwards.
Options
Prop
Type
Returns
Prop
Type
The sources stay the same while the graph is rebuilt, so components never need to resubscribe.