SpectrumSettings class final

Configuration for the real-time FFT spectrum + raw PCM streams.

Apply atomically via Player.setSpectrum (replace the whole bundle) or Player.updateSpectrum (mutate one or more fields with a copyWith mapper). Read live via PlayerStream.spectrum and PlayerStream.pcm.

The streams are lazy — the FFT pipeline allocates and the FFI poll loop starts only on the first listener, and tears down on the last cancel. A subscriber to either PlayerStream.spectrum or PlayerStream.pcm alone is enough to arm the pipeline; both streams share the same upstream tap.

Default values pick a balanced "music visualizer" preset: 2048-point Hann FFT at 30 Hz emit rate, log-spaced 64 bands from 20 Hz to 20 kHz, asymmetric EMA (fast attack, slow decay) and a [-70, -10] dB clip range that looks lively on most music. Tweak from there.

Constructors

SpectrumSettings({int fftSize = 2048, int bandCount = 64, double bandLowHz = 20.0, double bandHighHz = 20000.0, WindowFunction window = WindowFunction.hann, Duration emitInterval = const Duration(milliseconds: 33), double attackSmoothing = 0.5, double releaseSmoothing = 0.1, double minDb = -70.0, double maxDb = -10.0})
const

Properties

attackSmoothing double
EMA smoothing coefficient applied when a band's new value is higher than the previous frame. Range [0, 1]; higher = snappier attack. 0.5 default — visualizer pops with transients (kicks, snare hits) without flickering on noise.
final
bandCount int
Number of perceptual bands the FftFrame.bands field is bucketed into. Typical 32 / 64 / 128. Bands are log-spaced from bandLowHz to bandHighHz — geometric edges, ratio (bandHighHz / bandLowHz)^(1 / bandCount) per band.
final
bandHighHz double
Upper edge of the band axis, in Hz. Default 20 kHz (top of human hearing). Clamped at FFT time to the Nyquist limit (sampleRate / 2).
final
bandLowHz double
Lower edge of the band axis, in Hz. Default 20 Hz (bottom of human hearing).
final
emitInterval Duration
Time between FftFrame / PcmFrame emissions. 33 ms ≈ 30 fps (default), 16 ms ≈ 60 fps. Range 8 ms (~120 fps) to 67 ms (~15 fps); the pipeline is gated by this independently of the FFT block rate.
final
fftSize int
FFT size in samples. Power of 2 between 256 and 4096. Larger = better frequency resolution at the cost of time resolution (a 2048-point FFT @ 48 kHz spans 42.7 ms of audio). 2048 is the visualizer sweet spot — sub-50 Hz resolution to separate kick fundamentals from sub-bass, latency below the ~80 ms A/V sync threshold.
final
hashCode int
The hash code for this object.
no setteroverride
maxDb double
Upper edge of the dB clip range mapped to band value 1.0. Anything above maxDb saturates at 1.0. -10 dB default — the visualizer hits full scale on loud peaks before digital clipping.
final
minDb double
Lower edge of the dB clip range mapped to band value 0.0. Anything below minDb reads as silent. -70 dB default — leaves some "lift" in the visualizer for quiet passages.
final
releaseSmoothing double
EMA smoothing coefficient applied when a band's new value is lower than the previous frame. Range [0, 1]; lower = slower decay ("afterglow"). 0.1 default. Asymmetric attack / release is the standard choice — symmetric EMA is simultaneously sluggish on transients AND jittery on decays.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
window WindowFunction
Window function applied to each FFT block before transform. See WindowFunction for the trade-offs. Default Hann is the universal music-visualizer choice.
final

Methods

copyWith({int? fftSize, int? bandCount, double? bandLowHz, double? bandHighHz, WindowFunction? window, Duration? emitInterval, double? attackSmoothing, double? releaseSmoothing, double? minDb, double? maxDb}) SpectrumSettings
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
override

Constants

defaults → const SpectrumSettings
Default visualizer preset — 2048 Hann FFT at 30 fps with 64 log-spaced bands. Convenience setSpectrum(SpectrumSettings.defaults) to reset.