require("audio") capsaudio = capsaudio or Audio() local time = 0 local frame = 0 local function getpitch(offset) return 440 * 2 ^ ((offset - 48) / 12) end local function saw(offset) return (time * getpitch(offset))%1 end local function pwm(offset, w) w = w or 0.5 return (time * getpitch(offset))%1 > w and 1 or 0 end local function sin(offset) return math.sin(time * math.pi * 2 * getpitch(offset)) end local v local function tri(offset) v = (time * getpitch(offset))%1 return v > 0.5 and (-v + 1) or v end local function super(func, offset, detune, amount) local v = 0 for i = -amount, amount do v = v + func(offset + (i / detune)) end return v end local function waveform() --[[ local t = (time*8) local w = 0--pwm(30, math.tan(t)) if t%1 > 0.9 and t%1 < 0.95 then w = w + (math.random() * math.sin(t)) end if t%8 < 0.5 then w = w + math.random() end if (t%4 > 2 and t%4 < 2.6) then w = w + pwm(12) end if (t%4 > 2.6 and t%4 < 3) then w = w + pwm(0) end]] local w = pwm(30, 1) return w end local volume = 1 local value local source = here local orientation = Vector(1,1,1) local distance = 300 local doppler = 1 local function calcsource(eye, rgt, src, dist, fwd, vel) dist = dist or distance local vol = math.Clamp(-((eye - src):Length() / dist) + 1, 0, 1) local dot = rgt:Dot((src - eye):Normalize()) orientation.x = vol orientation.y = math.Clamp(-dot, 0, 1) + 0.5 orientation.z = math.Clamp(dot, 0, 1) + 0.5 return vol ~= 0 end function capsaudio.process(buffer) volume = GetConVarNumber("volume") --if not calcsource(LocalPlayer():EyePos(), LocalPlayer():EyeAngles():Right(), source, 300, LocalPlayer():GetAimVector(), LocalPlayer():GetVelocity()) then return end for i = 0, #buffer / 2 - 1 do value = waveform() * (volume * orientation.x) buffer[i * 2 + 1] = value * orientation.y buffer[i * 2 + 2] = value * orientation.z time = time + ((1 / capsaudio.rate) * doppler) end end capsaudio:start()