TheFakeFew

visualizer

Oct 25th, 2024 (edited)
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.97 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.  
  96. local spectrum = {}
  97. local rem = Instance.new("RemoteEvent", sg)
  98. rem.OnServerEvent:Connect(function(p, spec)
  99.     if(p ~= owner)then return end
  100.     task.defer(function()
  101.         spectrum = spec
  102.     end)
  103. end)
  104.  
  105. game:GetService("RunService").Heartbeat:Connect(function()
  106.     if(tick() - lastsync > 30)then
  107.         lastsync = tick()
  108.         mus.TimePosition = mus.TimePosition
  109.     end
  110.    
  111.     for i = 1, amount do
  112.         local v = spectrum[i] or 0
  113.         local height = v
  114.         local part = parts[i]
  115.  
  116.         if(part.Size.Y == size and height == 0)then continue end
  117.         local col = math.min(1, (height*(i/amount))+.25)
  118.         part.Color = part.Color:Lerp(Color3.new(col, col, col), .2)
  119.         part.Size = part.Size:Lerp(vector(size,height+size,size), .2)
  120.     end
  121.    
  122.     game:GetService("TweenService"):Create(base, TweenInfo.new(.3), {
  123.         CFrame = owner.Character.Head.CFrame*CFrame.new(0,3,0)*CFrame.Angles(0,math.rad(90),0)
  124.     }):Play()
  125. end)
  126.  
  127. local ls = NLS([=[
  128. local plr = owner or game:GetService("Players").LocalPlayer
  129. local Player = nil
  130. local Analyzer = nil
  131. local Wire = nil
  132.  
  133. local rem = script.Parent:WaitForChild("RemoteEvent")
  134. local mus = script:WaitForChild("Visualizer").Value:WaitForChild("Music").Sound
  135.  
  136. local cos, pi = math.cos, math.pi
  137. local function hanning(spectrum)
  138.     local N = #spectrum
  139.     local windowedSpectrum = {}
  140.  
  141.     for n = 0, N - 1 do
  142.         local hanningValue = 0.5 * (1 - cos((2 * pi * n) / (N - 1)))
  143.         windowedSpectrum[n + 1] = spectrum[n + 1] * hanningValue
  144.     end
  145.  
  146.     return windowedSpectrum
  147. end
  148.  
  149. local lastspectrum = {}
  150. local delta = 0
  151. game:GetService("RunService").RenderStepped:Connect(function(dt)
  152.     delta = delta + dt
  153.    
  154.     if(not Player or not Player:IsDescendantOf(plr.Character))then
  155.         pcall(game.Destroy, Player)
  156.         Player = Instance.new("AudioPlayer", plr.Character)
  157.     end
  158.     if(not Analyzer or not Analyzer:IsDescendantOf(Player))then
  159.         pcall(game.Destroy, Analyzer)
  160.         Analyzer = Instance.new("AudioAnalyzer", Player)
  161.     end
  162.     if(not Wire or not Wire:IsDescendantOf(Player))then
  163.         pcall(game.Destroy, Wire)
  164.         Wire = Instance.new("Wire", Player)
  165.     end
  166.     Wire.SourceInstance = Player
  167.     Wire.TargetInstance = Analyzer
  168.     Analyzer.SpectrumEnabled = true
  169.     Analyzer.WindowSize = Enum.AudioWindowSize.Medium
  170.    
  171.     Player.AssetId = mus.SoundId
  172.     Player.Looping = mus.Looped
  173.     Player.PlaybackSpeed = mus.Pitch
  174.     Player.TimePosition = mus.TimePosition
  175.     Player:Play()
  176.    
  177.    
  178.     local spectrum = Analyzer:GetSpectrum()
  179.     if(#spectrum < 10)then return end
  180.     for i, v in next, spectrum do spectrum[i] = v*800 end
  181.    
  182.     spectrum = hanning(spectrum)
  183.    
  184.     if(spectrum ~= lastspectrum and delta >= 1/60)then
  185.         delta = 0
  186.         lastspectrum = spectrum
  187.         rem:FireServer(spectrum)
  188.     end
  189. end)
  190. ]=], sg)
  191.  
  192. local v = Instance.new("ObjectValue", ls)
  193. v.Value = model
  194. v.Name = "Visualizer"
Advertisement
Add Comment
Please, Sign In to add comment