This commit is contained in:
2025-06-16 20:20:07 -04:00
parent 9584d4e517
commit e3970ac4ce

View File

@@ -30,32 +30,38 @@ end
-- end -- end
-- end -- end
-- end -- end
local function playSpeaker(speaker, input)
local function playFullFile(speaker, fileName)
local decoder = require("cc.audio.dfpwm").make_decoder() local decoder = require("cc.audio.dfpwm").make_decoder()
local decoded = decoder(input) local file = fs.open(fileName, "rb")
while not speaker.playAudio(decoded, 3) do
os.pullEvent("speaker_audio_empty") if not file then
print("Failed to open file: " .. fileName)
return
end 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
os.pullEvent("speaker_audio_empty")
end
end
file.close()
end end
local function playSound(speakers, fileName) local function playSound(speakers, fileName)
local fileStream = getFileName(fileName) local tasks = {}
local values = io.lines(fileStream, 16 * 1024) for _, speaker in ipairs(speakers) do
table.insert(tasks, function()
for input in values do playFullFile(speaker, fileName)
print("playing audio...") end)
-- Create parallel tasks, each with its own decoder instance
local tasks = {}
for _, speaker in ipairs(speakers) do
table.insert(tasks, function()
playSpeaker(speaker, input)
end)
end
-- Execute all in parallel
parallel.waitForAll(table.unpack(tasks))
end end
parallel.waitForAll(table.unpack(tasks))
end end