Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if SERVER then return end
- if not BASS then
- require("bass")
- if not BASS then return end -- uhh
- end
- flomp = flomp or {} local f = flomp
- flomp.emitter = ParticleEmitter(EyePos(), false)
- f.error_enums = {
- [1] = "mem",
- [2] = "fileopen",
- [3] = "driver",
- [4] = "buflost",
- [5] = "handle",
- [6] = "format",
- [7] = "position",
- [8] = "init",
- [9] = "start",
- [14] = "already",
- [18] = "nochan",
- [19] = "illtype",
- [20] = "illparam",
- [21] = "no3d",
- [22] = "noeax",
- [23] = "device",
- [24] = "noplay",
- [25] = "freq",
- [27] = "notfile",
- [29] = "nohw",
- [31] = "empty",
- [32] = "nonet",
- [33] = "create",
- [34] = "nofx",
- [37] = "notavail",
- [38] = "decode",
- [39] = "dx",
- [40] = "timeout",
- [41] = "fileform",
- [42] = "speaker",
- [43] = "version",
- [44] = "codec",
- [45] = "ended",
- [-1] = "unknown",
- }
- f.FFT = {}
- f.FFT_Bass_1 = 0
- f.FFT_Bass_2 = 0
- f.max_volume = 0
- f.scale = 1
- f.eye_angles = Angle(0)
- f.eye_origin = vector_origin
- f.vol_multplier = 1
- f.fft_detail = 6
- f.mul_fft = 1024/f.fft_detail
- for i = 1, 1024 do
- f.FFT[i] = 0
- end
- function flomp.SetSource(var)
- var = type(var) == "number" and Entity(var) or var
- if type(var) == "Vector" or (IsEntity(var) and var:IsValid()) then
- f.source = var
- end
- end
- function flomp.SetScale(n)
- f.scale = n
- end
- function flomp.SetVolumeInputScale(n)
- f.vol_multplier = n
- end
- function flomp.SetPow(n)
- f.pow = n
- end
- function flomp.GetPow()
- return f.pow or 1.3
- end
- function flomp.GetSourcePos()
- return type(f.source) == "Vector" and f.source or IsEntity(f.source) and f.source:IsValid() and f.source:GetPos() or vector_origin
- end
- function flomp.GetChannel()
- return f.channel
- end
- function flomp.PlaySound(path, restart, force_web)
- if restart == false and not f.IsNotReady() then return end
- --if f.channel then f.channel:stop() end
- f.channel = nil
- if force_web or path:find("://", nil, true) then
- BASS.StreamFileURL(path, -1, function(channel, err)
- if err ~= 0 then
- error("[BASS] Flomp Stream Error: " .. f.error_enums[err])
- end
- f.channel = f.channel or channel
- f.channel:play()
- end)
- else
- f.channel = f.channel or BASS.StreamFile(path)
- if not f.channel then
- error("[BASS Flomp could not open the file garrysmod/sound/" .. path)
- return end
- f.channel:play()
- end
- end
- function flomp.Stop()
- if f.channel then
- f.channel:stop()
- f.channel = nil
- end
- end
- function flomp.GetAverage(istart, iend)
- istart = math.Round(math.Clamp(istart, 1, 1024))
- iend = math.Round(math.Clamp(iend, 1, 1024))
- local n = 0
- for i=istart, iend do
- n = n + f.FFT[i]
- end
- local div = (iend - istart)
- return div == 0 and 0 or (n / div)
- end
- function flomp.IsAround(number, min, max)
- return number > min and number < max and true or false
- end
- function flomp.IsNotReady()
- return
- f.channel and not f.channel:getplaying() or
- not f.channel or
- not f.source or
- IsEntity(f.source) and not f.source:IsValid()
- end
- function flomp.ScaleVolume(volume)
- return ((volume ^ f.GetPow()) * 100) * f.vol_multplier
- end
- function flomp.Spectrum2D()
- if bawss and bawss.channel then bawss.channel:stop() bawss = nil end -- declan interuption protection
- do return end
- if f.IsNotReady() then return end
- local h = ScrH() + -40
- local w = ScrW()
- local volume = 0
- for fr = 1, 1024 do
- volume = f.ScaleVolume(f.FFT[fr])
- surface.SetDrawColor(volume,volume,255*volume,255)
- surface.DrawLine(
- (w+fr)-780, h,
- (w+fr)-780, h-(volume*50)
- )
- end
- end
- function flomp.ParticleThink()
- if f.IsNotReady() then return end
- if type(f.channel) == "Entity" and not f.channel:IsValid() then f.channel:stop() return end
- f.FFT = f.channel:fft2048()
- --local overall_volume = flomp.GetAverage(1, 1024)
- --if overall_volume > f.max_volume then
- --f.max_volume = overall_volume
- --print(overall_volume)
- --end
- f.FFT_Bass_1 = flomp.GetAverage(1, 15)
- for i = 1, 4 do
- local fr = (i * 256)
- --print(fr)
- local volume = f.ScaleVolume(f.FFT[math.Clamp(math.Round(i*f.mul_fft), 1, 1024)])
- if volume < 0.01 then continue end
- local n_fr = -(fr-30) + 1024 -- negative fr, 1024 to 0
- local f_fr = (fr-30)/1024 -- fraction fr, 0, 1
- local nf_fr = n_fr/1024 -- negative fraction, 1, 0
- for i = 1, math.Clamp(math.Round(volume*8*f.scale),0,8) do
- local size = (f.FFT_Bass_1 * 30 ^ 2)
- local color = HSVToColor(((CurTime()*10)+(f_fr*100))%360, 0.3, 1)
- local velocity = ((f.eye_origin - f.GetSourcePos() ):Normalize() * 2 + VectorRand()):GetNormal()* volume
- local particle = f.emitter:Add("particle/Particle_Glow_04_Additive", f:GetSourcePos() + (velocity*80*f.scale))
- particle:SetVelocity(velocity*1600*f.scale)
- particle:SetLifeTime(0)
- particle:SetDieTime(math.Clamp(volume^2, 0.1, 1))
- particle:SetStartLength(size*4*f.scale)
- particle:SetStartSize(size*f.scale)
- particle:SetEndSize(0)
- particle:SetStartAlpha(255)
- particle:SetEndAlpha(0)
- particle:SetAirResistance(math.Clamp((-size+800), 10, 1200)*f.scale)
- --particle:SetGravity((VectorRand()*100)*f.scale)
- particle:SetColor(color.r, color.g, color.b)
- particle:SetCollide(true)
- particle:SetBounce(0.1)
- end
- end
- end
- f.smooth_pp = 0
- function flomp.DrawPostProcess()
- if f.IsNotReady() then return end
- local w = ScrW()
- local h = ScrH()
- local vec2 = f.GetSourcePos():ToScreen()
- local m = math.max(f.eye_angles:Forward():DotProduct((f.GetSourcePos()-f.eye_origin):Normalize()), 0) ^ 3
- m = m * math.Clamp((-f.eye_origin:Distance(f.GetSourcePos()) / 6000) + 1, 0, 1)
- f.channel:setvolume(math.Clamp(m*10, 0, 1))
- if m < 0.001 then return end
- m = math.Clamp(m, 0, 1)
- local vol = f.FFT_Bass_1 * f.vol_multplier
- local avr = math.Clamp(vol * 2 - 0.1,0,1)
- local blur = math.Clamp((vol*-10)+1, 0.2, 1)
- local invert = (vol*-10+1)
- local darkness = (-m+1)
- local angle = VectorRand() * f.GetAverage(1, 5) ^ 2.2 * 60 * m
- angle.x = math.Clamp(angle.x, -0.2, 0.2)
- angle.y = math.Clamp(angle.y, -0.2, 0.2)
- angle.z = 0
- LocalPlayer():SetEyeAngles(LocalPlayer():EyeAngles() + angle)
- f.smooth_pp = f.smooth_pp + ((avr - f.smooth_pp)*FrameTime()*10)
- --local mscale = m * f.vol_multplier
- local tbl= {}
- tbl[ "$pp_colour_addr" ] = 3/255*m
- tbl[ "$pp_colour_addg" ] = 0
- tbl[ "$pp_colour_addb" ] = 4/255*m
- tbl[ "$pp_colour_brightness" ] = Lerp(m, 0, -0.11)
- tbl[ "$pp_colour_contrast" ] = Lerp(m, 2, 1.4)
- tbl[ "$pp_colour_colour" ] = 1.6
- tbl[ "$pp_colour_mulr" ] = 0
- tbl[ "$pp_colour_mulg" ] = 0
- tbl[ "$pp_colour_mulb" ] = 0
- DrawMotionBlur(blur, 0.5, 0)
- DrawSunbeams(darkness,math.max(vol*0.2, 0.1), 0.005 * (vol * 50), vec2.x / ScrW(), vec2.y / ScrH())
- DrawBloom(darkness, invert*(m/10), math.max(invert*40+2, 5), math.max(invert*40+2, 5), 4, 3, 1, 1, 1 )
- DrawColorModify(tbl)
- --print(blur)
- end
- function flomp.Calc3DSound(ply, origin, angles, fov)
- f.eye_origin = origin
- f.eye_angles = angles
- if f.IsNotReady() then return end
- if f.channel then
- if IsEntity(f.source) then
- f.channel:set3dposition(origin, angles:Forward()*-1, vector_origin or (f.source:GetVelocity()/100))
- else
- f.channel:set3dposition(origin, angles:Forward()*-1, vector_origin)
- end
- end
- BASS.SetPosition(origin, vector_origin or (ply:GetVelocity()/100), angles:Forward()*-1, angles:Up())
- end
- --hook.Add("HUDPaint", "flomp_Helper", flomp.Spectrum2D)
- hook.Add("Think", "flomp_Think", flomp.ParticleThink)
- hook.Add("RenderScreenspaceEffects", "flomp_RenderScreenspaceEffects", flomp.DrawPostProcess)
- hook.Add("CalcView", "flomp_CalcView", flomp.Calc3DSound)
- --flomp.SetSource(Vector(9663.96875,-6569.4130859375,-9824.2373046875))
- --flomp.PlaySound("http://listen.trancebase.fm/tunein-dsl-asx", false)
- flomp.SetVolumeInputScale(20)
- flomp.SetPow(1.4)
Advertisement
Add Comment
Please, Sign In to add comment