This commit is contained in:
2025-06-16 20:27:40 -04:00
parent e4a91a47a6
commit c76e8c9677

View File

@@ -17,58 +17,30 @@ local function randomFileName()
return name return name
end end
-- local function playSound(speaker, fileName) local function playFullFile(fileName)
-- local fileStream = getFileName(fileName) local fileStream = getFileName(fileName)
-- local values = io.lines(fileStream, 16 * 1024) local values = io.lines(fileStream, 16 * 1024)
-- for input in values do for input in values do
-- print("playing audo....") print("playing audo....")
-- local decoded = decoder(input) local decoded = decoder(input)
-- while not speaker.playAudio(decoded, 3) do
-- os.pullEvent("speaker_audio_empty")
-- end
-- end
-- end
local function playFullFile(speaker, fileName)
local decoder = require("cc.audio.dfpwm").make_decoder()
local file = fs.open(fileName, "rb")
if not file then
print("Failed to open file: " .. fileName)
return
end
while true do
local chunk = file.read(16 * 1024)
if not chunk then break end
local decoded = decoder(chunk)
while not speaker.playAudio(decoded, 3) do while not speaker.playAudio(decoded, 3) do
os.pullEvent("speaker_audio_empty") os.pullEvent("speaker_audio_empty")
end end
end end
file.close()
end end
local function playSound(placeholder,fileName) local function playSound(speaker, fileName)
local speakers = table.pack(peripheral.find("speaker")) local speakers = table.pack(peripheral.find("speaker"))
local tasks = {} local tasks = {}
for i = 1, speakers.n do for i = 1, speakers.n do
tasks[i] = function() tasks[i] = function()
playFullFile(speakers[i], fileName) playFullFile(speakers[i], fileName)
end end
end end
parallel.waitForAll(table.unpack(tasks, 1, speakers.n)) parallel.waitForAll(table.unpack(tasks, 1, speakers.n))
end end
local function playControlRoomAlarm(speakers) local function playControlRoomAlarm(speakers)
playSound(speakers,"short_control_alarm") playSound(speakers,"short_control_alarm")
end end