Spectrum

spectrumVisualizers

Plots 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/spectrum

Pulls in

use-audio-sourcecontrol-theme

First time? Add the registry to your components.json once:

components.json
{
  "registries": {
    "@syntho-ui": "https://engine.syntho.app/r/{name}.json"
  }
}

Usage

Controlled or uncontrolled, whichever suits the surrounding state.

example.tsx
import { Spectrum } from "@/components/ui/spectrum"

<Spectrum analyser={analyserNode} variant="bars" bars={48} />

Props

PropTypeDefaultDescription
analyserAnalyserNodeA live analyser to read frequency data from.
getData(target: Float32Array) => boolean | voidSupply dB magnitudes yourself instead of using an analyser.
variant"bars" | "curve""bars"Discrete bars, or a filled line across the bins.
barsnumber48Number of bars. Ignored by the curve variant.
scale"log" | "linear""log"Frequency axis scaling. Log is the musically useful one.
minFrequency / maxFrequencynumber20 / NyquistThe frequency range shown.
minDecibels / maxDecibelsnumber-90 / -10The magnitude range mapped to the display height.
sampleRatenumberNeeded for the frequency axis when driving from getData.
heightnumber140Display 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 slider and switch roles with live aria-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.