M MY Multiplayer: Wiki
Side
Kind

getSoundFFTData

Client

Returns the frequency spectrum of what the sound is playing right now, for building visualisers.

table|false getSoundFFTData(sound sound, int samples [, int bands = 0])

Parameters

NameTypeDescription
soundsoundThe sound element, or a dui element for the browser's sound.
samplesintHow many samples to analyse: a power of 2 from 256 to 16384.
bandsintGroup the spectrum into this many bands (up to half of samples). 0 returns the whole spectrum.default 0

Returns

A table of magnitudes from 0 to 1, or false if the arguments are not valid or the sound is paused, finished or streamed out.

Example

local music = playSound("sounds/track.mp3", true)

addEventHandler("onClientRender", root, function()
    local bands = getSoundFFTData(music, 2048, 32)
    if not bands then return end
    for i = 0, 31 do
        local h = math.min(bands[i] * 400, 200)
        dxDrawRectangle(20 + i * 12, 400 - h, 10, h, tocolor(80, 200, 255))
    end
end)
NoteThe table starts at index 0. Without bands it holds samples / 2 + 1 values; with bands it holds that many values, in logarithmically growing bands.

See also