Quick actions

cmd+k|ctrl+k

Navigation

Languages

frequency vis but local

Snippet info

Language

Lua

Visibility

public

Author

dinoturto

Created

2023-09-17T02:37:22.767387Z

Updated

2024-03-26T09:46:08.869147Z

local chr = owner.Character
local root = chr.HumanoidRootPart

script.Parent = chr

local visGui = Instance.new("BillboardGui")
visGui.Name = "visGui"
visGui.Adornee = root
visGui.Size = UDim2.new(8, 0, 4, 0)
visGui.StudsOffsetWorldSpace = Vector3.new(0, 1.5, 0)
visGui.Parent = root

local bg = Instance.new("Frame")
bg.Size = UDim2.new(0.8, 0, 1.4, 0)
bg.Position = UDim2.new(0.5, 0, -1.2, 0)
bg.BorderSizePixel = 0.5
bg.BackgroundColor3 = Color3.fromRGB(47, 47, 47)
bg.AnchorPoint = Vector2.new(0.5, 0)
bg.ZIndex = 0
bg.Parent = visGui

local barTemplate = Instance.new("Frame")
barTemplate.Size = UDim2.new(0.25, 1)
barTemplate.BorderSizePixel = 0
barTemplate.BackgroundColor3 = Color3.fromRGB(99, 254, 147)
barTemplate.ZIndex = 1

local sen = 20

local bars = {}
for i = 1, 44 do
    local bar = barTemplate:Clone()
    bar.Size = UDim2.new(0.0125, 0, 0, 0)
    bar.Position = UDim2.new(0.1875 + i / 70, 0, 0, 0)
    bar.ZIndex = 1
    bar.Parent = visGui
    table.insert(bars, bar)
end

local sound = Instance.new("AudioPlayer")
sound.Looping = true
sound.Parent = root

local soundAnalyze = Instance.new("AudioAnalyzer")
soundAnalyze.Parent = sound

local soundAnalyzeWire = Instance.new("Wire")
soundAnalyzeWire.SourceInstance = sound
soundAnalyzeWire.TargetInstance = soundAnalyze
soundAnalyzeWire.Parent = root

function blackman(fftTable)
    local windowSize = #fftTable
    local windowedData = {}
    for i = 1, windowSize do
        local a0 = 0.42659
        local a1 = 0.49656
        local a2 = 0.076849
        local windowValue = a0 - a1 * math.cos((2 * math.pi * (i - 1)) / (windowSize - 1)) + a2 * math.cos((4 * math.pi * (i - 1)) / (windowSize - 1))
        windowedData[i] = (fftTable[i] * windowValue) * 100
    end
    return windowedData
end

sound:Play()

local freq = {}

local song = Instance.new("Sound")
song.Name = "visSound"
song.SoundId = "rbxassetid://"
song.Volume = 2
song.Looped = true
song.Parent = root
song:Play()

owner.Chatted:Connect(function(msg)
    if string.sub(msg,1,3) == '/e ' then
        msg = msg:sub(4)
    end
    
    if msg:sub(1, 5) == "play " then
        song.SoundId = "rbxassetid://" .. msg:sub(6)
        sound.AssetId = "rbxassetid://" .. msg:sub(6)
        song:Play()
        sound:Play()
    elseif msg:sub(1, 4) == "vol " then
        song.Volume = msg:sub(5)
    elseif msg:sub(1, 4) == "pit " then
        song.PlaybackSpeed = msg:sub(5)
        sound.PlaybackSpeed = song.PlaybackSpeed
    elseif msg:sub(1, 4) == "sen " then
        sen = msg:sub(5)
    end
end)

game:GetService("RunService").PreRender:Connect(function(dt)
    local freq = soundAnalyze:GetSpectrum()
    for i, v in pairs(freq) do
        if i > 44 then
            table.remove(freq, i)
        end
    end
    
    blackman(freq)
    
    sound.TimePosition = song.TimePosition
    
    for i, v in next, bars do
        if freq[i] ~= nil then
            v.Size = v.Size:Lerp(UDim2.new(0.0125, 0, math.clamp(freq[i] * sen, 0, 1), 0), 0.3 * dt * 60)
        end
        v.Position = UDim2.new(0.175 + i / 70, 0, -v.Size.Height.Scale / 1.000001, 0)
    end
end)
INFO