Advertisement
Guest User

exampleadsr

a guest
Nov 26th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.06 KB | None | 0 0
  1. local component = require("component")
  2. local sound = component.sound
  3.  
  4. -- Reset Sound Card to known state
  5. sound.clear() -- clear out buffers
  6. sound.setTotalVolume(1) -- set overall volume to max
  7. for i = 1,8 do
  8.     sound.resetEnvelope(i) -- remove any ADSRs
  9.     sound.resetAM(i) -- remove any AM modulation
  10.     sound.resetFM(i) -- remove any FM modulation
  11.     sound.setVolume(i,1) -- set channel volume to max
  12.     sound.close(i) -- close channels (stop emitting audio)
  13. end
  14.  
  15. -- process commands
  16. while not sound.process() do
  17.     os.sleep(0.05)
  18. end
  19.  
  20. -- next statements add commands to the buffer
  21. sound.setWave(1, sound.modes.square) -- set channel 1 to square wave
  22. sound.setFrequency(1, 500) -- set channel 1 to 500Hz
  23. sound.setADSR(1, 100, 300, 0.5, 200) -- set channel 1 ADSR to Attack: 100ms, Decay: 300ms, Sustain: 50%, Release 200ms
  24. sound.open(1) -- open channel 1 (hit note)
  25. sound.delay(500) -- wait 500ms
  26. sound.close(1) -- close channel 1 (release note)
  27. sound.delay(200) -- wait 200ms (for ADSR Release)
  28.  
  29. -- process commands
  30. while not sound.process() do
  31.     os.sleep(0.05)
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement