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

View File

@@ -30,33 +30,39 @@ 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")
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
local function playSound(speakers, fileName) local function playSound(speakers, fileName)
local fileStream = getFileName(fileName)
local values = io.lines(fileStream, 16 * 1024)
for input in values do
print("playing audio...")
-- Create parallel tasks, each with its own decoder instance
local tasks = {} local tasks = {}
for _, speaker in ipairs(speakers) do for _, speaker in ipairs(speakers) do
table.insert(tasks, function() table.insert(tasks, function()
playSpeaker(speaker, input) playFullFile(speaker, fileName)
end) end)
end end
-- Execute all in parallel
parallel.waitForAll(table.unpack(tasks)) parallel.waitForAll(table.unpack(tasks))
end end
end