CapsAdmin

Untitled

Mar 29th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.37 KB | None | 0 0
  1. --if not LocalPlayer():CheckUserGroupLevel("developers") then return end
  2.  
  3. local mat_screenspace = Material("models/screenspace")
  4. local mdl_dome = Model("models/props_phx/construct/metal_dome360.mdl")
  5. local white = Color(255, 255, 255, 255)
  6.  
  7. SafeRemoveEntity(fractal_renderer)
  8.  
  9. local renderer = ClientsideModel(mdl_dome)
  10.  
  11. local function scale(ent, vec)
  12.     local mat = Matrix()
  13.     mat:Scale(vec)
  14.     ent:EnableMatrix("RenderMultiply", mat)
  15. end
  16.  
  17. RunConsoleCommand("pp_bloom", "1")
  18. RunConsoleCommand("pp_bloom_passes", "0")
  19. RunConsoleCommand("pp_bloom_multiply", "0")
  20. flomp = flomp or {} local f = flomp
  21. do -- particles
  22.    
  23.  
  24.     flomp.emitter = ParticleEmitter(EyePos(), false)
  25.     flomp.emitter:SetNoDraw(true)
  26.  
  27.     f.FFT = {}
  28.     f.FFT_Size = 1024
  29.  
  30.     f.FFT_Bass_1 = 0
  31.     f.FFT_Bass_2 = 0
  32.  
  33.     f.max_volume = 0
  34.     f.scale = 1
  35.     f.eye_angles = Angle(0)
  36.     f.eye_origin = vector_origin
  37.     f.vol_multplier = 1
  38.  
  39.     f.fft_detail = 10
  40.     f.mul_fft = f.FFT_Size/f.fft_detail
  41.  
  42.     for i = 1, f.FFT_Size do
  43.         f.FFT[i] = 0
  44.     end
  45.  
  46.     function flomp.SetSource(var)
  47.         var = type(var) == "number" and Entity(var) or var
  48.         if type(var) == "Vector" or (IsEntity(var) and var:IsValid()) then
  49.             f.source = var
  50.         end
  51.     end
  52.  
  53.     function flomp.SetScale(n)
  54.         f.scale = n
  55.     end
  56.  
  57.     function flomp.SetVolumeInputScale(n)
  58.         f.vol_multplier = n
  59.     end
  60.  
  61.     function flomp.GetSourcePos()
  62.         return type(f.source) == "Vector" and f.source or IsEntity(f.source) and f.source:IsValid() and f.source:EyePos() or vector_origin
  63.     end
  64.  
  65.     function flomp.GetAverage(istart, iend)
  66.         istart = math.Round(math.Clamp(istart, 1, f.FFT_Size))
  67.         iend = math.Round(math.Clamp(iend, 1, f.FFT_Size))
  68.         local n = 0
  69.         for i=istart, iend do
  70.         --  if f.FFT[i] then
  71.                 n = n + f.FFT[i]
  72.     --      end
  73.         end
  74.  
  75.         local div = (iend - istart)
  76.  
  77.         return div == 0 and 0 or (n / div)
  78.     end
  79.  
  80.     function flomp.IsAround(number, min, max)
  81.         return number > min and number < max and true or false
  82.     end
  83.  
  84.     function flomp.ScaleVolume(volume, peak)
  85.         return ((volume ^ flomp.powscale) * f.vol_multplier) * 2.5
  86.     end
  87.  
  88.     function flomp.Spectrum2D()
  89.         do return end
  90.         --if bawss and bawss.channel then bawss.channel:stop() bawss = nil end -- declan interuption protection
  91.  
  92.         local h = ScrH() + -400
  93.         local w = ScrW()
  94.         local volume = 0
  95.  
  96.         for fr = 1, f.FFT_Size do
  97.             volume = f.ScaleVolume(f.FFT[fr])
  98.  
  99.             surface.SetDrawColor(volume,volume,255*volume,255)
  100.             surface.DrawLine(
  101.                 (w+fr)-ScrW(), h,
  102.                 (w+fr)-ScrW(), h-(volume*50)
  103.             )
  104.         end
  105.     end
  106.  
  107.     local time = 0
  108.  
  109.     function flomp.SpectrumUpdate(data, peak)
  110.         if flomp.sound_vol == 0 then return end
  111.         f.FFT = data
  112.  
  113.         f.FFT_Bass_1 = flomp.GetAverage(1, 6)
  114.        
  115.         time = time + f.FFT_Bass_1 * 50
  116.  
  117.         for i = 1, 4 do
  118.  
  119.             local fr = (i * 256)
  120.  
  121.             local volume = f.ScaleVolume(f.FFT[math.Clamp(math.Round(i*f.mul_fft), 1, f.FFT_Size)], peak)
  122.  
  123.             if volume < 0.01 then continue end
  124.  
  125.             local n_fr = -(fr-30) + f.FFT_Size -- negative fr, f.FFT_Size to 0
  126.  
  127.             local f_fr = (fr-30)/f.FFT_Size -- fraction fr, 0, 1
  128.             local nf_fr = n_fr/f.FFT_Size -- negative fraction, 1, 0
  129.  
  130.             local max = 32
  131.            
  132.             for i2 = 1, max do
  133.                 local pi = (i2/max) * math.pi * 2
  134.  
  135.                 local size = (f.FFT_Bass_1 * 50 ^ 1.5)
  136.                 local color = HSVToColor((time+(pi*volume))%360, 1, 1)
  137.                
  138.                 local velocity = Vector(math.sin(pi+i+time), -volume / 5, math.cos(pi+i+time)) * volume ^ 1.3
  139.                 velocity = velocity
  140.  
  141.                 local particle = f.emitter:Add("sprites/light_glow02_add", f:GetSourcePos() + (velocity*5*f.scale))
  142.  
  143.                 particle:SetVelocity(velocity*1000*f.scale)
  144.  
  145.                 particle:SetLifeTime(0)
  146.                 particle:SetDieTime(math.Clamp(volume*0.1, 0.1, 0.8))
  147.  
  148.                 particle:SetStartLength(size*3*f.scale * 2*2)
  149.                 particle:SetEndLength(size*1.5*f.scale)
  150.                 particle:SetStartSize(size*f.scale*volume*0.5*2)
  151.                 particle:SetEndSize(0)
  152.  
  153.                 particle:SetStartAlpha(20)
  154.                 particle:SetEndAlpha(0)
  155.  
  156.                 particle:SetAirResistance(math.Clamp((-size+800), 10, 1200)*f.scale)
  157.                 --particle:SetGravity((VectorRand()*50)*f.scale)
  158.  
  159.                 particle:SetColor(color.r, color.g, color.b)
  160.                 particle:SetCollide(true)
  161.                 particle:SetBounce(0.1)
  162.             end
  163.         end
  164.        
  165.         flomp.SpectrumUpdate2(data)
  166.     end
  167.        
  168.     function flomp.SpectrumUpdate2(data)
  169.  
  170.         for i = 1, 4 do
  171.  
  172.             local fr = (i * 256)
  173.  
  174.             local volume = f.ScaleVolume(f.FFT[math.Clamp(math.Round(i*f.mul_fft), 1, f.FFT_Size)])
  175.  
  176.             if volume < 0.01 then continue end
  177.  
  178.             local n_fr = -(fr-30) + f.FFT_Size -- negative fr, f.FFT_Size to 0
  179.  
  180.             local f_fr = (fr-30)/f.FFT_Size -- fraction fr, 0, 1
  181.             local nf_fr = n_fr/f.FFT_Size -- negative fraction, 1, 0
  182.  
  183.             for i = 1, math.Clamp(math.Round(volume*4),0,15) do
  184.  
  185.                 local size = (f.FFT_Bass_1 * 15 ^ 1.8)
  186.                 local color = HSVToColor((time+(f_fr+volume*100))%360, f.FFT_Bass_1*20, 1)
  187.                 local velocity = ((f.eye_origin - f.GetSourcePos() ):Normalize() * 2 + VectorRand()):GetNormal()* volume ^ 2 * 3
  188.  
  189.                 local particle = f.emitter:Add("sprites/light_glow02_add", f:GetSourcePos() + (velocity*5*f.scale))
  190.  
  191.                 particle:SetVelocity(velocity*300*f.scale*2)
  192.  
  193.                 particle:SetLifeTime(0)
  194.                 particle:SetDieTime(math.Clamp(volume*0.3, 0.1, 0.8)^1.5)
  195.  
  196.                 particle:SetStartLength(size*7*f.scale*2)
  197.                 particle:SetEndLength(size*2*f.scale*4)
  198.                 particle:SetStartSize(size*f.scale*4)
  199.                 particle:SetEndSize(0)
  200.  
  201.                 particle:SetStartAlpha(255)
  202.                 particle:SetEndAlpha(0)
  203.  
  204.                 particle:SetAirResistance(math.Clamp((-size+800), 10, 2000)*f.scale*1.5)
  205.                 --particle:SetGravity((VectorRand()*50)*f.scale)
  206.  
  207.                 particle:SetColor(color.r, color.g, color.b)
  208.                 particle:SetCollide(true)
  209.                 particle:SetBounce(0.1)
  210.             end
  211.         end
  212.     end
  213.  
  214.     f.smooth_pp = 0
  215.     f.look_at_mult = 0
  216.  
  217.     function flomp.DrawPostProcess()
  218.         if flomp.sound_vol == 0 then return end
  219.         local w = ScrW()
  220.         local h = ScrH()
  221.  
  222.         local vec2 = f.GetSourcePos():ToScreen()
  223.  
  224.         local m = math.max(f.eye_angles:Forward():DotProduct((f.GetSourcePos()-f.eye_origin):GetNormalized()), 0) ^ 3
  225.         f.look_at_mult = m
  226.         m = m * (f.sound_vol * 2) ^ 2
  227.         m = m / 5
  228.        
  229.         --m = m * math.Clamp((-f.eye_origin:Distance(f.GetSourcePos()) / 15000) + 1, 0, 1)
  230.    
  231.         if m < 0.001 then return end
  232.  
  233.         m = math.Clamp(m, 0, 1)
  234.  
  235.         local vol = f.FFT_Bass_1
  236.         local darkness = (-m+1)
  237.  
  238.         local avr = math.Clamp(vol * 2  - 0.1,0,1) * m
  239.         local blur = math.Clamp((vol*-0.5)+1, 0.2, 1)
  240.         local invert = (vol*-10+1)
  241.  
  242.         local angle = Angle(math.Rand(-1,1), math.Rand(-1,1), math.Rand(-1,1)) * f.GetAverage(3, 7) * m
  243.         angle.x = math.Clamp(angle.p, -0.52, 0.52)
  244.         angle.y = math.Clamp(angle.y, -0.52, 0.52)
  245.         angle.z = 0
  246.         LocalPlayer():SetEyeAngles(LocalPlayer():EyeAngles() + angle)
  247.  
  248.         f.smooth_pp = f.smooth_pp + ((avr - f.smooth_pp)*FrameTime()*10)
  249.  
  250.         local mscale = m * f.vol_multplier
  251.  
  252.         local tbl= {}
  253.         tbl[ "$pp_colour_addr" ] = 0
  254.         tbl[ "$pp_colour_addg" ] = 0
  255.         tbl[ "$pp_colour_addb" ] = 0
  256.         tbl[ "$pp_colour_brightness" ] = -0.1
  257.         tbl[ "$pp_colour_contrast" ] = 1.1-m
  258.         tbl[ "$pp_colour_colour" ] = 1.25+(m^0.75)
  259.         tbl[ "$pp_colour_mulr" ] = 0
  260.         tbl[ "$pp_colour_mulg" ] = 0
  261.         tbl[ "$pp_colour_mulb" ] = 0
  262.  
  263.  
  264.         --DrawMotionBlur(blur, 1, 0)
  265.         --DrawBloom(darkness, invert*m, math.max(invert*20+2, 5), math.max(invert*20+10, 5), 4, 10, 1, 1, 1 )
  266.         DrawSunbeams(0.99, math.max(vol/4, 0.1), 0.2, vec2.x / ScrW(), vec2.y / ScrH())
  267.         DrawColorModify(tbl)
  268.         --DrawToyTown(Lerp(avr, 0, 10), ScrH()*0.55)
  269.         DrawSharpen(m*5,m)
  270.        
  271.         local avr = (flomp.GetAverage(3, 5) * 2.5) ^ 1.5
  272.         flomp.fov = Lerp(avr ^ 1.5, 150, 60)
  273.     end
  274.  
  275.     hook.Add("HUDPaint", "flomp_Helper", flomp.Spectrum2D)
  276.     hook.Add("RenderScreenspaceEffects", "flomp_RenderScreenspaceEffects", flomp.DrawPostProcess)
  277.  
  278.  
  279.     hook.Add("RenderScene", "flomp_CalcView", function(pos, ang)
  280.         f.eye_origin = pos
  281.         f.eye_angles = ang
  282.     end)
  283.  
  284.     local voldata = Vector(0,0,0) -- V, L, R
  285.  
  286.     local function calcsource(eye, rgt, src, dist, fwd, vel)
  287.         local vol = math.Clamp(-((eye - src):Length() / dist) + 1, 0, 1)
  288.         local dot = rgt:Dot((src - eye):GetNormalized())
  289.  
  290.         local left = math.Clamp(-dot, 0, 1) + 0.5
  291.         local right = math.Clamp(dot, 0, 1) + 0.5
  292.  
  293.         if vol ~= 0 then
  294.             return vol, -left + right
  295.         end
  296.     end
  297.  
  298.     function GetVolumeData(source, falloff)
  299.         local ply = LocalPlayer()
  300.         return calcsource(ply:EyePos(),f.eye_angles:Right(), source, falloff, f.eye_angles:Forward(), ply:GetVelocity())
  301.     end
  302.  
  303.     f.sound_vol = 0
  304.  
  305.     hook.Add("Think","flomp_volume",function()
  306.         local vol, panning = GetVolumeData(flomp.GetSourcePos(), 4000)
  307.  
  308.         if vol then
  309.             f.sound_vol = vol
  310.             if not f.wowo then vol = vol * f.look_at_mult end
  311.            
  312.             hook.Call("FlompVolume", GAMEMODE, (vol^1.5)*2, panning)
  313.         else
  314.             hook.Call("FlompVolume", GAMEMODE, 0, 0)
  315.         end
  316.     end)
  317.  
  318.  
  319.     hook.Add("HUDPaintBackground", "itsaparty")
  320.     hook.Add("CalcView", "itsaparty")
  321.    
  322.    
  323.     local last_peak = 1
  324.     hook.Add("Spectrum", "flomp_spectrum", function(fft)
  325.        
  326.         local peak = 0
  327.        
  328.         for k,v in pairs(fft) do
  329.             peak = math.max(peak, v)
  330.             fft[k] = (fft[k] ^ 1.75) * 0.75
  331.         end
  332.        
  333.         last_peak = 0
  334.        
  335.         flomp.SpectrumUpdate(fft, peak)
  336.     end)
  337. end
  338.  
  339. local size = 30
  340.  
  341. flomp.fov = 75-40
  342. local t = 0
  343. local offset = 6
  344.  
  345. function renderer:RenderOverride()
  346.     cam.Start3D(EyePos() + (EyeAngles():Right() * offset) + (EyeAngles():Up() * offset), EyeAngles(), (flomp.fov or 0) + 40)
  347.     --self:SetAngles(Angle(90,90, t*50%360))
  348.     render.SuppressEngineLighting(true)
  349.         render.MaterialOverride(mat_screenspace)
  350.         --render.DrawSphere(self:GetPos(), -50, 32, 32, white)
  351.        
  352.         render.SetBlend(0.9)
  353.         self:SetRenderOrigin(self:GetPos() + self:GetUp() * -size)
  354.         scale(self, Vector(1,1,1) * size)
  355.         self:SetupBones()
  356.         self:DrawModel()
  357.        
  358.         render.CullMode(MATERIAL_CULLMODE_CW)
  359.         self:SetRenderOrigin(self:GetPos() + self:GetUp() * size)
  360.         scale(self, Vector(1,-1,1) * size)
  361.         self:SetupBones()
  362.         self:DrawModel()
  363.         render.MaterialOverride()
  364.         render.CullMode(MATERIAL_CULLMODE_CCW)
  365.        
  366.         render.SetBlend(1)
  367.        
  368.         self:SetRenderOrigin()
  369.     render.SuppressEngineLighting(false)
  370.    
  371.     flomp.SetSource(self:GetPos())
  372.     cam.End3D()
  373. end
  374.  
  375. SafeRemoveEntity(fractal_tree)
  376.  
  377. local tree = ClientsideModel("models/props_combine/combine_bridge.mdl")
  378. tree:SetPos(LocalPlayer():EyePos() + LocalPlayer():GetAimVector() * 20)
  379. timer.Simple(0.1, function()
  380.     function tree:RenderOverride()
  381.         t = t + flomp.FFT_Bass_1 / 1000
  382.        
  383.         --render.SetBlend(0.999)
  384.         for i = 0, 16 do
  385.             i = (i / 16) * 360
  386.             scale(self, Vector(5,math.cos(t)*4,5))
  387.             self:SetAngles(Angle(t+i, 0, math.sin(t)*180))
  388.             self:SetupBones()
  389.             render.SuppressEngineLighting(true)
  390.             render.MaterialOverride(mat_screenspace)
  391.             self:DrawModel()
  392.             render.MaterialOverride()
  393.             render.SuppressEngineLighting(false)
  394.         end
  395.         --render.SetBlend(1)
  396.        
  397.         self:SetPos(fractal_renderer:GetPos() + fractal_renderer:GetUp() * 200)
  398.        
  399.         cam.IgnoreZ(true)
  400.         flomp.emitter:SetPos(self:GetPos())
  401.         flomp.emitter:Draw()
  402.         cam.IgnoreZ(false)
  403.     end
  404. end)
  405.  
  406. fractal_tree = tree
  407.  
  408. renderer:Spawn()
  409.  
  410.  
  411. flomp.SetScale(1)
  412. flomp.SetVolumeInputScale(6)
  413. flomp.powscale = 3
  414.  
  415. fractal_renderer = renderer
  416.  
  417.  
  418. hook.Add("RenderScene", "flomp_CalcView", function(pos, ang)
  419.     f.eye_origin = pos
  420.     f.eye_angles = ang
  421. end)
  422.  
  423. local voldata = Vector(0,0,0) -- V, L, R
  424.  
  425. local function calcsource(eye, rgt, src, dist, fwd, vel)
  426.     local vol = math.Clamp(-((eye - src):Length() / dist) + 1, 0, 1)
  427.     local dot = rgt:Dot((src - eye):Normalize())
  428.  
  429.     local left = math.Clamp(-dot, 0, 1) + 0.5
  430.     local right = math.Clamp(dot, 0, 1) + 0.5
  431.  
  432.     if vol ~= 0 then
  433.         return vol, -left + right
  434.     end
  435. end
  436.  
  437. function GetVolumeData(source, falloff)
  438.     local ply = LocalPlayer()
  439.     return calcsource(ply:EyePos(),f.eye_angles:Right(), source, falloff, f.eye_angles:Forward(), ply:GetVelocity())
  440. end
  441.  
  442. f.sound_vol = 0
  443.  
  444. hook.Add("Think","flomp_volume",function()
  445.     local vol, panning = GetVolumeData(flomp.GetSourcePos(), 7000)
  446.  
  447.     if vol then
  448.         f.sound_vol = vol
  449.        
  450.         if not f.wowo then
  451.             vol = vol * f.look_at_mult
  452.         end
  453.        
  454.         vol = vol * GetConVarNumber("volume")
  455.        
  456.         if GetConVarNumber("snd_mute_losefocus") == 1 and not system.HasFocus() then
  457.             vol = 0
  458.         end
  459.                
  460.         hook.Call("FlompVolume", GAMEMODE, (vol^1.5)*2, panning)
  461.     else
  462.         hook.Call("FlompVolume", GAMEMODE, 0, 0)
  463.     end
  464.    
  465.     renderer:SetPos(Vector(2070.5473632812, -4751.162109375, -10755.232421875))
  466.     tree:SetPos(renderer:GetPos())
  467.     renderer:SetAngles(Angle(90,90,0))
  468.     renderer:SetRenderBounds(Vector(1,1,1)*-size*100, Vector(1,1,1)*size*100)
  469.     flomp.SetSource(renderer:GetPos())
  470. end)
  471.  
  472. function flomp.Panic()
  473.     if html and html:IsValid() then html:Remove() end
  474.     SafeRemoveEntity(renderer)
  475.     SafeRemoveEntity(fractal_tree)
  476.     hook.Remove("Think", "flomp_volume")
  477.     hook.Remove("HUDPaint", "flomp_Helper")
  478.     hook.Remove("RenderScreenspaceEffects", "flomp_RenderScreenspaceEffects")
  479.     hook.Remove("RenderScene", "flomp_CalcView")
  480.     hook.Remove("Spectrum", "flomp_spectrum")
  481. end
  482.  
  483. hook.Add("HUDPaintBackground", "itsaparty")
  484. hook.Add("CalcView", "itsaparty")
  485.  
  486.  
  487. local last_peak = 1
  488. hook.Add("Spectrum", "flomp_spectrum", function(fft)
  489.    
  490.     local peak = 0
  491.    
  492.     for k,v in pairs(fft) do
  493.         peak = math.max(peak, v)
  494.         fft[k] = (fft[k] ^ 2)
  495.     end
  496.    
  497.     last_peak = 0
  498.    
  499.     flomp.SpectrumUpdate(fft, peak)
  500. end)
  501.    
  502. flomp.SetScale(0.4)
  503. flomp.SetVolumeInputScale(2)
  504.  
  505. flomp.powscale = 2
  506.  
  507. hook.Add("HUDPaintBackground", "itsaparty")
  508. hook.Add("CalcView", "itsaparty")
  509.  
  510.  
  511. function startmusic(URL)
  512.     URL = URL or "http://dl.dropbox.com/u/244444/slamtheclown.ogg"
  513.  
  514.     if _G.html and _G.html:IsValid() then _G.html:Remove() end
  515.  
  516.     local html = vgui.Create("HTML") _G.html = html
  517.  
  518.     html:AddFunction("gmod", "print", print)
  519.     html:AddFunction("gmod", "data", function(data)
  520.         if flomp.sound_vol == 0 then return end
  521.         pcall(function()
  522.             local data = CompileString(data, "data")()
  523.             hook.Call("Spectrum", nil, data)
  524.         end)
  525.     end)
  526.  
  527.     local player = setmetatable(
  528.         {
  529.         },
  530.         {
  531.             __index = function(self, func_name)
  532.                 return function(...)
  533.                     local tbl = {...}
  534.                    
  535.                     for key, val in pairs(tbl) do
  536.                         tbl[key] = tostring(val)
  537.                        
  538.                         if tbl[key] == "nil" or tbl[key] == "NULL" then
  539.                             tbl[key] = "null"
  540.                         end
  541.                     end
  542.                    
  543.                     local str = ("%s(%q)"):format(func_name, table.concat(tbl, ", "))
  544.                     html:QueueJavascript(str)
  545.                     --print(str)
  546.                 end
  547.             end
  548.         }
  549.     )
  550.  
  551.     html:SetPos(ScrW(), ScrH())
  552.     html:OpenURL("http://dl.dropbox.com/u/244444/gmod_audio.html")
  553.     html:QueueJavascript[[
  554.         var AudioContext = window.AudioContext || window.webkitAudioContext;
  555.  
  556.         window.onerror = function(desc, file, line)
  557.         {
  558.             gmod.print(desc)
  559.             gmod.print(file)
  560.             gmod.print(line)
  561.         }
  562.  
  563.         var audio = new AudioContext
  564.         var analyser = audio.createAnalyser()
  565.         analyser.connect(audio.destination)
  566.        
  567.         setInterval(
  568.             function()
  569.             {
  570.                 var spectrum = new Uint8Array(analyser.frequencyBinCount);
  571.                 analyser.getByteFrequencyData(spectrum);
  572.                
  573.                 var lol = new Array(spectrum.length);
  574.                
  575.                 for(var i = 0; i < spectrum.length; ++i)
  576.                     lol[i] = spectrum[i] / 255;
  577.                
  578.                 gmod.data("return {" + lol.join(",") + "}");
  579.             },
  580.             15
  581.         );
  582.        
  583.         function download(url, callback)
  584.         {
  585.             var request = new XMLHttpRequest
  586.            
  587.             request.open("GET", url, true)
  588.             request.responseType = "arraybuffer"
  589.             request.send(null)
  590.            
  591.             request.onload = function()
  592.             {
  593.                 gmod.print("loaded \"" + url + "\"")
  594.                 gmod.print("status " + request.status)
  595.                 callback(request.response)
  596.             }
  597.            
  598.             request.onprogress = function(event)
  599.             {
  600.                 gmod.print(Math.round(event.loaded / event.total * 100) + "%")
  601.             }      
  602.         }
  603.        
  604.         var source = audio.createBufferSource()
  605.         var volctrl = audio.createGainNode()
  606.        
  607.         function play(url)             
  608.         {              
  609.             download(url, function(data)
  610.             {
  611.                 gmod.print("decoding " + data.byteLength + " ...")
  612.                 audio.decodeAudioData(data, function(buffer)
  613.                 {
  614.                     source = audio.createBufferSource()
  615.                    
  616.                     source.connect(analyser)
  617.                     analyser.connect(volctrl)
  618.                     volctrl.connect(audio.destination)
  619.                    
  620.                     source.buffer = buffer
  621.                     source.loop = true
  622.                     source.noteOn(0)
  623.                    
  624.                     gmod.print("LOADED AND DECODED")
  625.                 },
  626.                 function(err)
  627.                 {
  628.                     gmod.print("decoding error " + err)
  629.                 })
  630.             })
  631.         }
  632.        
  633.         function SetVolume(vol)
  634.         {
  635.             if(volctrl) volctrl.gain.value = vol
  636.         }
  637.     ]]
  638.  
  639.     player.play(URL)
  640.     timer.Remove("fractals")
  641.     timer.Simple(1, function()
  642.         hook.Add("FlompVolume", "flomp_html_volume", function(vol)
  643.             if not html and html:IsValid() then return end
  644.             player.SetVolume(vol-1)
  645.         end)
  646.     end)
  647. end
  648.  
  649. if not html then
  650.     startmusic()
  651. end
Advertisement
Add Comment
Please, Sign In to add comment