updated
This commit is contained in:
@@ -30,32 +30,38 @@ end
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
local function playSpeaker(speaker, input)
|
||||
|
||||
local function playFullFile(speaker, fileName)
|
||||
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
|
||||
os.pullEvent("speaker_audio_empty")
|
||||
end
|
||||
end
|
||||
|
||||
file.close()
|
||||
end
|
||||
|
||||
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 = {}
|
||||
for _, speaker in ipairs(speakers) do
|
||||
table.insert(tasks, function()
|
||||
playSpeaker(speaker, input)
|
||||
playFullFile(speaker, fileName)
|
||||
end)
|
||||
end
|
||||
|
||||
-- Execute all in parallel
|
||||
parallel.waitForAll(table.unpack(tasks))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user