CapsAdmin

Untitled

Nov 21st, 2011
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.19 KB | None | 0 0
  1. require("audio")
  2.  
  3. capsaudio = capsaudio or Audio()
  4. local time = 0
  5. local frame = 0
  6.  
  7. local function getpitch(offset)
  8.     return 440 * 2 ^ ((offset - 48) / 12)
  9. end
  10.  
  11. local function saw(offset)
  12.     return (time * getpitch(offset))%1
  13. end
  14.  
  15. local function pwm(offset, w)
  16.     w = w or 0.5
  17.  
  18.     return (time * getpitch(offset))%1 > w and 1 or 0
  19. end
  20.  
  21. local function sin(offset)
  22.     return math.sin(time * math.pi * 2 * getpitch(offset))
  23. end
  24.  
  25. local v
  26. local function tri(offset)
  27.     v = (time * getpitch(offset))%1
  28.  
  29.     return v > 0.5 and (-v + 1) or v
  30. end
  31.  
  32. local function super(func, offset, detune, amount)
  33.     local v = 0
  34.     for i = -amount, amount do
  35.         v = v + func(offset + (i / detune))
  36.     end
  37.  
  38.     return v
  39. end
  40.  
  41. local function waveform()
  42.    --[[ local t = (time*8)
  43.     local w = 0--pwm(30, math.tan(t))
  44.  
  45.     if t%1 > 0.9 and t%1 < 0.95 then
  46.         w = w + (math.random() * math.sin(t))
  47.     end
  48.  
  49.     if t%8 < 0.5 then
  50.         w = w + math.random()
  51.     end
  52.  
  53.     if (t%4 > 2 and t%4 < 2.6) then
  54.         w = w + pwm(12)
  55.     end
  56.  
  57.     if (t%4 > 2.6 and t%4 < 3) then
  58.         w = w + pwm(0)
  59.     end]]
  60.  
  61.     local w = pwm(30, 1)
  62.  
  63.     return w
  64. end
  65.  
  66. local volume = 1
  67. local value
  68. local source = here
  69. local orientation = Vector(1,1,1)
  70.  
  71. local distance = 300
  72. local doppler = 1
  73.  
  74. local function calcsource(eye, rgt, src, dist, fwd, vel)
  75.     dist = dist or distance
  76.  
  77.     local vol = math.Clamp(-((eye - src):Length() / dist) + 1, 0, 1)
  78.     local dot = rgt:Dot((src - eye):Normalize())
  79.  
  80.     orientation.x = vol
  81.  
  82.     orientation.y = math.Clamp(-dot, 0, 1) + 0.5
  83.     orientation.z = math.Clamp(dot, 0, 1) + 0.5
  84.  
  85.     return vol ~= 0
  86. end
  87.  
  88. function capsaudio.process(buffer)
  89.     volume = GetConVarNumber("volume")
  90.  
  91.     --if not calcsource(LocalPlayer():EyePos(), LocalPlayer():EyeAngles():Right(), source, 300, LocalPlayer():GetAimVector(), LocalPlayer():GetVelocity()) then return end
  92.  
  93.     for i = 0, #buffer / 2 - 1 do
  94.         value = waveform() * (volume * orientation.x)
  95.  
  96.         buffer[i * 2 + 1] = value * orientation.y
  97.         buffer[i * 2 + 2] = value * orientation.z
  98.         time = time + ((1 / capsaudio.rate) * doppler)
  99.     end
  100.  
  101. end
  102.  
  103. capsaudio:start()
  104.  
  105.  
Add Comment
Please, Sign In to add comment