CapsAdmin

Untitled

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