92 lines
2.1 KiB
Lua
92 lines
2.1 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 playSound(speaker, fileName)
|
|
local fileStream = getFileName(fileName)
|
|
local values = io.lines(fileStream, 16 * 1024)
|
|
for input in values do
|
|
print("playing audo....")
|
|
local decoded = decoder(input)
|
|
while not speaker.playAudio(decoded) do
|
|
os.pullEvent("speaker_audio_empty")
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
local function playControlRoomAlarm(speakers)
|
|
playSound(speakers,"short_control_alarm")
|
|
end
|
|
|
|
local function playExternalAlarm(speakers)
|
|
playSound(speakers,"external_alarm")
|
|
end
|
|
local function playInternalAlarm(speakers)
|
|
playSound(speakers,"internal_alarm")
|
|
end
|
|
|
|
|
|
local function createSoundFile(fileName)
|
|
--local placeholder = "https://git.astrocore.space/root/NovaCorpLLC/raw/branch/main/placeholder.dfpwm"
|
|
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, name)
|
|
|
|
--print("Added placeholder sound file: " .. name)
|
|
|
|
local response = http.get(fullPath)
|
|
|
|
print("Downloading sound file: " .. name)
|
|
|
|
local fileData = response.readAll()
|
|
|
|
local file = fs.open(name,"w")
|
|
|
|
file.write(fileData)
|
|
file.close()
|
|
|
|
response.close()
|
|
end
|
|
|
|
|
|
|
|
function addSoundFile(fileName)
|
|
createSoundFile(fileName)
|
|
end
|
|
|
|
local function watch()
|
|
end
|
|
|
|
|
|
local function startup()
|
|
local sounds = {
|
|
{ fileName = "short_control_alarm" },
|
|
{ fileName = "external_alarm" },
|
|
{ fileName = "internal_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, playControlRoomAlarm = playControlRoomAlarm, addSoundFile = addSoundFile } |