refactor: streamline sound playback logic and remove unused function

This commit is contained in:
2025-06-16 20:32:39 -04:00
parent c76e8c9677
commit 48dfa77350

View File

@@ -17,29 +17,45 @@ local function randomFileName()
return name return name
end end
local function playFullFile(fileName)
local fileStream = getFileName(fileName) local function playSingleSound(speaker, values)
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 speaker.playAudio(decoded, 3)
os.pullEvent("speaker_audio_empty")
end
end end
end end
local function playSound(speaker, fileName) local function playSound(speaker, fileName)
local fileStream = getFileName(fileName)
local values = io.lines(fileStream, 16 * 1024)
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) playSingleSound(speakers[i], values)
end end
end end
parallel.waitForAll(table.unpack(tasks, 1, speakers.n)) parallel.waitForAll(table.unpack(tasks, 1, speakers.n))
end 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, 3) do
-- os.pullEvent("speaker_audio_empty")
-- end
-- end
-- end
local function playControlRoomAlarm(speakers) local function playControlRoomAlarm(speakers)
playSound(speakers,"short_control_alarm") playSound(speakers,"short_control_alarm")