Spectrum
spectrumVisualizersPlots magnitude against frequency on a logarithmic axis, because a linear one spends half its width above 10 kHz — where almost nothing musically interesting happens — and crushes the bass into a few pixels. Each bar takes the loudest bin in its band, so a narrow peak is never averaged into invisibility.
Synthetic signal for display only — this demo produces no audio.
Install
Copies the source into your project. Anything it depends on comes with it.
$ npx shadcn add @syntho-ui/spectrumPulls in
use-audio-sourcecontrol-theme
First time? Add the registry to your components.json once:
{
"registries": {
"@syntho-ui": "https://engine.syntho.app/r/{name}.json"
}
}Usage
Controlled or uncontrolled, whichever suits the surrounding state.
import { Spectrum } from "@/components/ui/spectrum"
<Spectrum analyser={analyserNode} variant="bars" bars={48} />Props
| Prop | Type | Default | Description |
|---|---|---|---|
| analyser | AnalyserNode | — | A live analyser to read frequency data from. |
| getData | (target: Float32Array) => boolean | void | — | Supply dB magnitudes yourself instead of using an analyser. |
| variant | "bars" | "curve" | "bars" | Discrete bars, or a filled line across the bins. |
| bars | number | 48 | Number of bars. Ignored by the curve variant. |
| scale | "log" | "linear" | "log" | Frequency axis scaling. Log is the musically useful one. |
| minFrequency / maxFrequency | number | 20 / Nyquist | The frequency range shown. |
| minDecibels / maxDecibels | number | -90 / -10 | The magnitude range mapped to the display height. |
| sampleRate | number | — | Needed for the frequency axis when driving from getData. |
| height | number | 140 | Display height in pixels; width defaults to 100%. |
Interaction
- Drag with pointer capture, so the gesture keeps tracking past the edge of the control.
- Shift while dragging for a fine pass; release it mid-gesture and coarse tracking resumes.
- Double-click resets to
defaultValue. - Arrow keys step normally, Shift+arrow steps finely, PageUp/PageDown jump by ten, Home/End go to the extremes.
- Proper
sliderandswitchroles with livearia-valuetext, so a screen reader announces the formatted value rather than the raw number. - The scroll wheel adjusts the value while the pointer is over the control; stepped ranges move at least one declared step per notch by default.