CapsAdmin

Untitled

Sep 26th, 2011
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.65 KB | None | 0 0
  1. require("audio")
  2.  
  3. capsaudio = capsaudio or Audio()
  4. local time = 0
  5.  
  6. local function getpitch(offset)
  7.     return 440 * 2 ^ ((offset - 48) / 12)
  8. end
  9.  
  10. local function saw(offset)
  11.     return (time * getpitch(offset))%1
  12. end
  13.  
  14. local function pwm(offset, w)
  15.     w = w or 0.5
  16.    
  17.     return (time * getpitch(offset))%1 > w and 1 or 0
  18. end
  19.  
  20. local function sin(offset)
  21.     return math.sin(time * math.pi * 2 * getpitch(offset))
  22. end
  23.  
  24. local v
  25. local function tri(offset)
  26.     v = (time * getpitch(offset))%1
  27.    
  28.     return v > 0.5 and (-v + 1) or v
  29. end
  30.  
  31. local function waveform()
  32.     return tri(62)
  33. end
  34.  
  35. local volume = 1
  36. local value
  37. local source = here
  38. local orientation = Vector(0,0,0)
  39.  
  40. local distance = 300
  41. local doppler = 1
  42.  
  43. local function calcsource(eye, rgt, src, dist, fwd, vel)
  44.     dist = dist or distance
  45.    
  46.     local vol = math.Clamp(-((eye - src):Length() / dist) + 1, 0, 1)
  47.     local dot = rgt:Dot((src - eye):Normalize())
  48.    
  49.     orientation.x = vol
  50.      
  51.     orientation.y = math.Clamp(dot, 0, 1) + 0.5
  52.     orientation.z = math.Clamp(-dot, 0, 1) + 0.5
  53.  
  54.     return vol ~= 0
  55. end
  56.  
  57. function capsaudio.process(buffer)
  58.     volume = GetConVarNumber("volume")
  59.                
  60.     if not calcsource(LocalPlayer():EyePos(), LocalPlayer():EyeAngles():Right(), source, 300, LocalPlayer():GetAimVector(), LocalPlayer():GetVelocity()) then return end
  61.    
  62.     for i = 0, #buffer / 2 - 1 do
  63.         value = waveform() * (volume * orientation.x)
  64.        
  65.         buffer[i * 2 + 1] = value * orientation.y
  66.         buffer[i * 2 + 2] = value * orientation.z
  67.         time = time + ((1 / capsaudio.rate) * doppler)
  68.     end
  69. end
  70.  
  71. capsaudio:start()
  72.  
  73.  
Advertisement
Add Comment
Please, Sign In to add comment