Files
nova-corp/speaker_driver.lua
2025-06-15 18:51:18 -04:00

75 lines
1.7 KiB
Lua

local dfpwm = require("cc.audio.dfpwm")
local encoder = dfpwm.make_encoder()
local decoder = dfpwm.make_decoder()
local function getFileName(name)
local extension = ".dfpwm"
local fullFile = name .. extension
return fullFile
end
local function getSoundUrl(fileName)
local baseRoute = "https://git.astrocore.space/root/NovaCorpLLC/raw/branch/main/"
local name = getFileName(fileName)
local fullPath = baseRoute .. name
return fullPath
end
local function getSoundStream(fileName)
local request = http.get(getSoundUrl(fileName))
print(textutils.serialize(request.getResponseHeaders()))
request.close()
end
local function playSound(speaker, fileName)
local values = io.lines(getSoundStream(fileName), 16 * 1024)
for input in values do
local decoded = decoder(input)
while not speaker.playAudio(decoded) do
os.pullEvent("speaker_audio_empty")
end
end
end
function playControlRoomAlarm(speakers)
for _, speaker in ipairs(speakers) do
playSound(speaker,"control_alarm")
end
end
function addSoundFile(fileName)
local baseRoute = "https://git.astrocore.space/root/NovaCorpLLC/raw/branch/main/"
local name = getFileName(fileName)
local fullPath = baseRoute .. name
shell.execute("rm", name)
shell.execute("wget", fullPath)
end
local function watch()
end
local function startup()
-- local sounds = {
-- { fileName = "control_alarm" }
-- }
-- for i, item in ipairs(sounds) do
-- addSoundFile(item.fileName)
-- end
end
local function shutdown()
end
local function report()
end
return { report = report, watch = watch, startup = startup, shutdown = shutdown }