Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require("audio")
- capsaudio = capsaudio or Audio()
- local time = 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 waveform()
- return tri(62)
- end
- local volume = 1
- local value
- local source = here
- local orientation = Vector(0,0,0)
- 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()
Advertisement
Add Comment
Please, Sign In to add comment