From 48dfa77350f5da64fbdd98fc82cd963065f00c6a Mon Sep 17 00:00:00 2001 From: itzmarkoni Date: Mon, 16 Jun 2025 20:32:39 -0400 Subject: [PATCH] refactor: streamline sound playback logic and remove unused function --- speaker_driver.lua | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/speaker_driver.lua b/speaker_driver.lua index 3346beb..433d8c9 100644 --- a/speaker_driver.lua +++ b/speaker_driver.lua @@ -17,29 +17,45 @@ local function randomFileName() return name end -local function playFullFile(fileName) - local fileStream = getFileName(fileName) - local values = io.lines(fileStream, 16 * 1024) + +local function playSingleSound(speaker, values) + 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 + speaker.playAudio(decoded, 3) end end local function playSound(speaker, fileName) + + local fileStream = getFileName(fileName) + local values = io.lines(fileStream, 16 * 1024) + local speakers = table.pack(peripheral.find("speaker")) local tasks = {} + for i = 1, speakers.n do tasks[i] = function() - playFullFile(speakers[i], fileName) + playSingleSound(speakers[i], values) end end + parallel.waitForAll(table.unpack(tasks, 1, speakers.n)) 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) playSound(speakers,"short_control_alarm")