LoveGmod1

red-fm-client-radio.lua

Jun 23rd, 2023
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. local dfpwm = require("cc.audio.dfpwm")
  2. local speaker = peripheral.find("speaker")
  3. local protocol = "red-fm"
  4.  
  5. term.clear()
  6. term.setCursorPos(1,1)
  7.  
  8. peripheral.find("modem", rednet.open)
  9.  
  10. print(protocol.." > Synchronisé")
  11. term.setCursorPos(1,2)
  12. print("Maintenez CTRL + T pour arrêter la radio")
  13.  
  14. while true do
  15. local id, message = rednet.receive(protocol)
  16. local file = fs.open("red-fm.dfpwm", "wb")
  17. file.write(message)
  18. file.flush()
  19. file.close()
  20.  
  21. local decoder = dfpwm.make_decoder()
  22. for chunk in io.lines("red-fm.dfpwm", 16 * 1024) do
  23. local buffer = decoder(chunk)
  24.  
  25. while not speaker.playAudio(buffer) do
  26. os.pullEvent("speaker_audio_empty")
  27. end
  28. end
  29. end
Add Comment
Please, Sign In to add comment