Quick actions

cmd+k|ctrl+k

Navigation

Languages

live wav

Snippet info

Language

Lua

Visibility

public

Author

thosewhoknow

Created

2025-01-01T14:30:09.172454Z

Updated

2025-01-05T16:20:00.857281Z

function sigma()
	local s = ""
	for i = 1, 8 do
		s ..= string.char(math.random(32, 126))
	end
	return s
end

local fDataHolder = Instance.new("ScreenGui")
fDataHolder.Name = sigma()
fDataHolder.ResetOnSpawn = false
fDataHolder.Parent = owner.PlayerGui

local fDataEvent = Instance.new("RemoteEvent")
fDataEvent.Name = sigma()
fDataEvent.Parent = fDataHolder

local Object = {}
Object.__index = Object

function new(className)
	return function(properties): Instance
		local obj =
			className == "MeshPart" and game:GetService("InsertService"):CreateMeshPartAsync(
				tostring(properties["MeshId"]
				) or "", properties.CollisionFidelity or Enum.CollisionFidelity.Default, properties.RenderFidelity or Enum.RenderFidelity.Automatic)
			or Instance.new(className)
		for propName, propVal in properties do
			if propName == "MeshId" or propName == "CollisionFidelity" or propName == "RenderFidelity" then
				continue	
			end
			if propName == "Children" then
				for _, child in propVal do
					child.Parent = obj
				end
				continue
			end
			obj[propName] = propVal
		end
		return obj
	end
end

local radioPart = new "MeshPart" {
	MeshId = "rbxassetid://1323932869",
	TextureID = "rbxassetid://1323932922",
	CanCollide = false,
	Children = {
		new "BillboardGui" {
			Active = true,
			ClipsDescendants = true,
			Size = UDim2.fromScale(5, 1),
			StudsOffsetWorldSpace = Vector3.new(0, 3, 0),
			ZIndexBehavior = Enum.ZIndexBehavior.Sibling,

			Children = {
				new "TextLabel" {
					FontFace = Font.new("rbxasset://fonts/families/RobotoMono.json"),
					Text = "155.05kHz | AM",
					TextColor3 = Color3.fromRGB(255, 255, 255),
					TextScaled = true,
					TextSize = 14,
					TextWrapped = true,
					BackgroundColor3 = Color3.fromRGB(255, 255, 255),
					BackgroundTransparency = 1,
					BorderColor3 = Color3.fromRGB(0, 0, 0),
					BorderSizePixel = 0,
					Size = UDim2.fromScale(1, 1),
				},
			}
		}
	}
}

local radioWeld = new "Weld" {
	Part0 = owner.Character.Torso,
	Part1 = radioPart,
	C1 = CFrame.new(1, -0.369, 0.065) * CFrame.Angles(0, math.rad(-90), math.rad(10))
}

radioWeld.Parent = radioPart

radioPart.Parent = script

local windowSize = 512
local baseComponentFrequency = 440
local playbackSpeed = 1
local volume = 1
local bitCrush = 1
local timePosition = 0

local waves = {}
local function makeSine(i, frequency)
	local s = Instance.new("Sound")
	s.SoundId = "rbxassetid://9040512197"
	s.Volume = 0
	s.Playing = true
	s.Looped = true
	s.Parent = owner.Character.HumanoidRootPart
	s.Name = i
	s.RollOffMaxDistance = 100

	local freqPbs = frequency / baseComponentFrequency

	if freqPbs > 20 then
		freqPbs = frequency / 1050
		s.SoundId = "rbxassetid://198099744"
	end
	s.PlaybackSpeed = freqPbs

	return s
end

for i = 0, windowSize / 2  do
	table.insert(waves, makeSine(i, 0))
end

-- exists for config ui and fft

local client = game:GetService("HttpService"):GetAsync("https://glot.io/snippets/h39os1nlye/raw/dio.lua")

NLS(client, fDataEvent)

local apiUrl, freq, band = "", 738, "AM"

local fftBuffers = {}

fDataEvent.OnServerEvent:Connect(function(plr, a, b)
	if a == "SetOptions" then
		if b.apiUrl then
			apiUrl = b.apiUrl
		end
		if b.freq then
			freq = b.freq
		end
		if b.band then
			band = b.band
		end
		radioPart.BillboardGui.TextLabel.Text = string.format("%dkHz | %s", freq, band)
	elseif a == "FFTData" then
		table.insert(fftBuffers, b)
	end
end)

function decodePacket(packet: buffer)
	local r, im = {}, {}
	local doubles = buffer.len(packet) // 8
	local j = 0
	for i = 1, doubles do
		local r2, i2 = buffer.readf32(packet, j), buffer.readf32(packet, j+4)
		r[i], im[i] = r2, i2
		j += 8
	end
	return r, im
end

local samplingRate = 24000

task.defer(function()
	while true do
		if apiUrl ~= "" then
			local d = game:GetService("HttpService"):GetAsync(string.format("%s/data", apiUrl))
			if d == "nobuffers" then
				return
			end
			fDataEvent:FireClient(owner, "GetAudioData", { data = buffer.fromstring(d) })
		end
		task.wait(0.5)
	end	
end)


game:GetService("RunService").PostSimulation:Connect(function(dt)
	if #fftBuffers > 0 then
		local packet = table.remove(fftBuffers, 1)
		local reals, imaginaries = decodePacket(packet)
		for i, wave in pairs(waves) do
			local real = reals[i]
			local imaginary = imaginaries[i]
			local magnitude = Vector2.new(real, imaginary).Magnitude
			local phase = math.atan2(imaginary, real)

			local pit = ((i - 1) * (samplingRate / windowSize)) * math.abs(playbackSpeed)
			local crossPoint = pit / baseComponentFrequency > 20 and 2.531 or 0.812
			local halfWavePeriod = pit / baseComponentFrequency > 20 and (1 / 1050 / 2) or (1 / baseComponentFrequency / 2)

			if not wave or wave.Parent ~= owner.Character.HumanoidRootPart then
				wave:Destroy()
				waves[i] = makeSine(i - 1, pit)
				wave = waves[i]
			end
			wave.TimePosition = crossPoint + (phase / math.pi) * halfWavePeriod
			wave.Volume = magnitude * 0.01 * volume
		end
	else
		for i, wave in pairs(waves) do
			wave.Volume = 0
		end
	end
end)
INFO