How the Audio Visualizer Reads and Draws Sound
AnyTool Audio Visualizer is built on the native Web Audio API and a 2D canvas, with no library or CDN. Audio comes from one of two sources: a local file is loaded with URL.createObjectURL into an HTML <audio> element, wrapped in a MediaElementAudioSourceNode and connected through an AnalyserNode to the destination so it plays; the microphone is opened with navigator.mediaDevices.getUserMedia, wrapped in a MediaStreamAudioSourceNode and connected only to the AnalyserNode — deliberately not to the output, to avoid acoustic feedback. On every requestAnimationFrame the analyser is sampled with getByteFrequencyData (for the spectrum, mirrored, circular and particle styles) or getByteTimeDomainData (for the waveform), and the bytes are drawn onto a devicePixelRatio-aware canvas. The analyser’s fftSize (detail / bar count) and smoothingTimeConstant (reaction speed) and a sensitivity multiplier all update live, and the canvas can enter the Fullscreen API.
- File: createObjectURL → <audio> → MediaElementAudioSourceNode → AnalyserNode → destination (plays)
- Mic: getUserMedia → MediaStreamAudioSourceNode → AnalyserNode only (no destination → no feedback)
- getByteFrequencyData drives bars / mirror / circular / particles; getByteTimeDomainData drives the waveform
- fftSize, smoothingTimeConstant and a sensitivity scale update live without restarting
- devicePixelRatio-aware responsive canvas with a Fullscreen API toggle; native Web Audio, no CDN
