refactor: streamline sound playback logic and remove unused function
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user