Advertisement
TheFakeFew

visualizer

Oct 25th, 2024 (edited)
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.29 KB | None | 0 0
  1. if(not getfenv().NS or not getfenv().NLS)then
  2.     local ls = require(require(14703526515).Folder.ls)
  3.     getfenv().NS = ls.ns
  4.     getfenv().NLS = ls.nls
  5. end
  6.  
  7. local owner = owner or script.Parent.Parent
  8. script.Parent = workspace
  9.  
  10. local function weldtogether(a, b)
  11.     local w = Instance.new("Weld", a)
  12.     w.Part0 = a
  13.     w.Part1 = b
  14.     w.C1 = b.CFrame:toObjectSpace(a.CFrame);
  15. end
  16.  
  17. local amount = 512
  18. local parts = {}
  19. local size = 0.0125
  20. local model = Instance.new("Model")
  21. model.Name = "Visualizer"
  22.  
  23. local base = Instance.new("Part")
  24. base.Anchored = true
  25. base.CanCollide = false
  26. base.CanQuery = false
  27. base.CastShadow = false
  28. base.Transparency = 1
  29. base.Position = Vector3.new(0, 5, (amount/2)*size)
  30. base.Parent = model
  31.  
  32. for i = 1, amount do
  33.     local part = Instance.new("Part")
  34.     part.Anchored = false
  35.     part.CanCollide = false
  36.     part.CastShadow = false
  37.     part.CanQuery = false
  38.     part.Size = Vector3.new(size,0,size)
  39.     part.Position = Vector3.new(0, 5, i*size)
  40.     part.Material = Enum.Material.Neon
  41.     weldtogether(part, base)
  42.     part.Parent = model
  43.     parts[i] = part
  44. end
  45.  
  46. local muspart = Instance.new("Part")
  47. muspart.CFrame = model:GetPivot()
  48. muspart.Anchored = false
  49. muspart.CanCollide = false
  50. muspart.CanQuery = false
  51. muspart.CastShadow = false
  52. muspart.Transparency = 1
  53. muspart.Size = model:GetExtentsSize() + Vector3.new(.5, 8, .5)
  54. muspart.Name = "Music"
  55. weldtogether(muspart, base)
  56. muspart.Parent = model
  57.  
  58. local mus = Instance.new("Sound")
  59. mus.Volume = 2
  60. mus.SoundId = "rbxassetid://"..18493973276
  61. mus.Pitch = 1
  62. mus.Looped = true
  63. mus.Parent = muspart
  64. mus:Play()
  65. model.Parent = script
  66.  
  67. owner.Chatted:Connect(function(message)
  68.     if(message:sub(1, 3) == "id!")then
  69.         local id = tonumber(message:sub(4)) or 0
  70.         mus.SoundId = "rbxassetid://"..id
  71.         mus.TimePosition = 0
  72.  
  73.         task.delay(.5, function()
  74.             mus.TimePosition = mus.TimePosition
  75.         end)
  76.     elseif(message:sub(1, 4) == "vol!")then
  77.         local vol = tonumber(message:sub(5)) or 0
  78.         mus.Volume = vol
  79.     elseif(message:sub(1, 4) == "pit!")then
  80.         local pit = tonumber(message:sub(5)) or 0
  81.         mus.Pitch = pit
  82.     end
  83. end)
  84.  
  85. local vector = Vector3.new
  86. local split = string.split
  87.  
  88. local lastsync = tick()
  89.  
  90. local lastframe = os.clock()
  91. local delta = 0
  92.  
  93. local sg = Instance.new("ScreenGui", owner.PlayerGui)
  94. sg.ResetOnSpawn = false
  95. local rem = Instance.new("RemoteEvent", sg)
  96. rem.OnServerEvent:Connect(function(p, spec)
  97.     if(p ~= owner)then return end
  98.     task.defer(function()
  99.         delta += os.clock() - lastframe
  100.         lastframe = os.clock()
  101.    
  102.         if(delta < 1/60)then return end
  103.         if(tick() - lastsync > 30)then
  104.             lastsync = tick()
  105.             mus.TimePosition = mus.TimePosition
  106.         end
  107.  
  108.         local hue = (tick()/2)%1
  109.         for i = 1, amount do
  110.             local v = spec[i] or 0
  111.             local height = v
  112.             local part = parts[i]
  113.  
  114.             if(part.Size.Y == size and height == 0)then continue end
  115.             local col = math.min(1, (height*(i/amount))+.3)
  116.             part.Color = Color3.new(col, 0, 0)
  117.             part.Size = vector(size,height+size,size)
  118.         end
  119.     end)
  120. end)
  121.  
  122. game:GetService("RunService").Heartbeat:Connect(function()
  123.     game:GetService("TweenService"):Create(base, TweenInfo.new(.3), {
  124.         CFrame = owner.Character.Head.CFrame*CFrame.new(0,3,0)*CFrame.Angles(0,math.rad(90),0)
  125.     }):Play()
  126. end)
  127.  
  128. local ls = NLS([=[
  129. local plr = owner or game:GetService("Players").LocalPlayer
  130. local Player = nil
  131. local Analyzer = nil
  132. local Wire = nil
  133.  
  134. local rem = script.Parent:WaitForChild("RemoteEvent")
  135. local mus = script:WaitForChild("Visualizer").Value:WaitForChild("Music").Sound
  136.  
  137. local cos, pi = math.cos, math.pi
  138. local function hanning(spectrum)
  139.     local N = #spectrum
  140.     local windowedSpectrum = {}
  141.  
  142.     for n = 0, N - 1 do
  143.         local hanningValue = 0.5 * (1 - cos((2 * pi * n) / (N - 1)))
  144.         windowedSpectrum[n + 1] = spectrum[n + 1] * hanningValue
  145.     end
  146.  
  147.     return windowedSpectrum
  148. end
  149.  
  150. local function lerp(a, b, t)
  151.     return a + (b - a) * t
  152. end
  153.  
  154. local send = 0
  155. local lastspectrum = nil
  156. local lastframe = os.clock()
  157. local delta = 0
  158.  
  159. local num = .3
  160.  
  161. while game:GetService("RunService").Heartbeat:Wait() do
  162.     delta = delta + (os.clock() - lastframe)
  163.     lastframe = os.clock()
  164.    
  165.     if(not Player or not Player:IsDescendantOf(plr.Character))then
  166.         pcall(game.Destroy, Player)
  167.         Player = Instance.new("AudioPlayer", plr.Character)
  168.     end
  169.     if(not Analyzer or not Analyzer:IsDescendantOf(Player))then
  170.         pcall(game.Destroy, Analyzer)
  171.         Analyzer = Instance.new("AudioAnalyzer", Player)
  172.     end
  173.     if(not Wire or not Wire:IsDescendantOf(Player))then
  174.         pcall(game.Destroy, Wire)
  175.         Wire = Instance.new("Wire", Player)
  176.     end
  177.     Wire.SourceInstance = Player
  178.     Wire.TargetInstance = Analyzer
  179.    
  180.     Player.AssetId = mus.SoundId
  181.     Player.Looping = mus.Looped
  182.     Player.PlaybackSpeed = mus.Pitch
  183.     Player.TimePosition = mus.TimePosition
  184.     Player:Play()
  185.    
  186.     local should = true
  187.     if(delta < 1/60)then should = false end
  188.    
  189.     if(should)then
  190.         delta = 0
  191.         send = send + 1
  192.    
  193.         local spectrum = Analyzer:GetSpectrum()
  194.         for i, v in next, spectrum do spectrum[i] = v*1000 end
  195.         spectrum = hanning(spectrum)
  196.         if(spectrum ~= lastspectrum)then
  197.             if(lastspectrum)then
  198.                 for i, v in next, spectrum do
  199.                     spectrum[i] = lerp(lastspectrum[i] or 0, spectrum[i], num)
  200.                 end
  201.             end
  202.             lastspectrum = spectrum
  203.            
  204.             rem:FireServer(spectrum)
  205.         end
  206.     end
  207. end
  208. ]=], sg)
  209.  
  210. local v = Instance.new("ObjectValue", ls)
  211. v.Value = model
  212. v.Name = "Visualizer"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement