updated
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user