Skip to content

Api > AudioSource > GetSpectrumData()


AudioSource.GetSpectrumData(number Length, number channel, FFTWindow window)⚓︎

Provides a block of the currently playing audio source's spectrum data.
The array given in the samples parameter will be filled with the requested data.

Parameters:⚓︎

Name Type Description
Length number Length of the block of the Spectrum Data to be returned. Must be a power of 2.
channel number The channel to sample from.
window FFTWindow The FFTWindow type to use when sampling.

Returns:⚓︎

type Description
number[] The array populated with audio samples.

Usage⚓︎

---@type AudioSource
local audiosource;

---@type number
local Length;

---@type number
local channel;

---@type FFTWindow
local window;


local val0 = audiosource.GetSpectrumData(Length, channel, window)

Extra Detail⚓︎

Number of values (the length of the samples array provided) must be a power of 2. (ie 128/256/512 etc). Min = 64. Max = 8192. Use window to reduce leakage between frequency bins/bands. Note, the more complex window type, the better the quality, but reduced speed.