fix: use pcall to uncapped AUDIO_VOLUME for HQ speakers while keeping 3.0 fallback for vanilla speakers

This commit is contained in:
2026-08-02 08:53:49 +08:00
parent 832658ad58
commit ac8405e300
2 changed files with 29 additions and 15 deletions
+24 -9
View File
@@ -1127,10 +1127,15 @@ local function queueSamplesSynchronized(samples, volume, playSeq)
if shouldStop(playSeq) then return false end
for name, sp in pairs(pending) do
local ok = false
pcall(function()
local safeVolume = math.min(volume or 3, 3.0)
ok = sp.playAudio(samples, safeVolume)
local success, err = pcall(function()
ok = sp.playAudio(samples, volume)
end)
if not success then
-- Fallback for vanilla speakers which throw an error if volume > 3.0
pcall(function()
ok = sp.playAudio(samples, 3.0)
end)
end
if ok then
pending[name] = nil
end
@@ -1161,12 +1166,18 @@ local function playChunkOnSpeakers(samples, volume, playSeq, waitForDrain)
if shouldStop(playSeq) then return false end
for name, sp in pairs(pending) do
local ok = false
pcall(function()
local success, err = pcall(function()
if type(sp.playAudio) == "function" then
local safeVolume = math.min(volume or 3, 3.0)
ok = sp.playAudio(samples, safeVolume)
ok = sp.playAudio(samples, volume)
end
end)
if not success then
pcall(function()
if type(sp.playAudio) == "function" then
ok = sp.playAudio(samples, 3.0)
end
end)
end
if ok then
usedNativePath = true
pending[name] = nil
@@ -1189,10 +1200,14 @@ local function playChunkOnSpeakers(samples, volume, playSeq, waitForDrain)
while true do
if shouldStop(playSeq) then return false end
local ok = false
pcall(function()
local safeVolume = math.min(volume or 3, 3.0)
ok = controller.playAudioAll(samples, safeVolume)
local success, err = pcall(function()
ok = controller.playAudioAll(samples, volume)
end)
if not success then
pcall(function()
ok = controller.playAudioAll(samples, 3.0)
end)
end
if ok then break end
local ev = { os.pullEvent() }
if ev[1] == "audio_interrupt" and tonumber(ev[2]) and tonumber(ev[2]) >= playSeq then