Advertisement
Guest User

examplesound

a guest
Nov 26th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.91 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.open(1) -- open channel 1 (allow to emit audio)
  24. sound.delay(500) -- wait 500ms
  25. sound.close(1) -- close channel 1 (stop emitting audio)
  26.  
  27. -- process commands
  28. while not sound.process() do
  29.     os.sleep(0.05)
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement