Sound driving DOM in a canvas

The card below is HTML drawn through a fragment shader. Press play on its <audio> controls. An AnalyserNode writes the level of four frequency bands to four CSS custom properties. The shader reads them as uniforms and the bars read them with CSS. The text field and the buttons keep working.

Test tones

Ten seconds, looped. A low beat, four notes and a high warble.

Press play on the card. Sound analysis starts with the first tap.

Show the code sound → custom properties → shader
  1. The markup. An ordinary card with an <audio controls> element. fx names the effect.
  2. Sound to four numbers. The audio element is routed through an AnalyserNode. Each frame, four bands of its spectrum are written to custom properties.
  3. Picture and sound in step. The levels are held back by the output latency the context reports.
  4. The CSS. The bars use the four properties directly.
  5. The effect. The same four properties arrive in the shader as u_amount, u_xy and u_progress.
  6. Inside the library: the upload and the draw.

How it works

Live checks

Each check builds its own fixture in a corner of the window. The card above isn't touched.

ResultExperimentDetail

Findings

From Chromium 157 with software rendering. The rows above say what your browser does.