Skip to content

Instantly share code, notes, and snippets.

@Bioscreeper
Created March 30, 2024 11:15
Show Gist options
  • Save Bioscreeper/a0d8e8869d94e0c2822fdb36aa62269a to your computer and use it in GitHub Desktop.
Save Bioscreeper/a0d8e8869d94e0c2822fdb36aa62269a to your computer and use it in GitHub Desktop.
--Copyright Dr
local listen = {ch=65500,id=1000}
local dfpwm = require("cc.audio.dfpwm")
local decoders = {left=dfpwm.make_decoder(),right=dfpwm.make_decoder()}
repeat --Find a wireless modem to listen with
for _,dev in ipairs({peripheral.find("modem")}) do
if dev.isWireless and dev.isWireless() then modem=dev end
end
until modem
modem.open(listen.ch)
while true do
local eventData={os.pullEvent("modem_message")}
if eventData[3]==listen.ch and eventData[4]==listen.id then
local unpack=string.unpack("s1s1s2",eventData[5])
local leftSample,rightSample=unpack[3]:sub(1,6000),unpack[3]:sub(6001,12000)
local leftAudio,rightAudio=decoders.left(leftSample),decoders.right(rightSample)
peripheral.call("left","playAudio",leftAudio)
peripheral.call("right","playAudio",rightAudio)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment