fix(audio): 修复非高音质环境下 PCM 音频分片播放时的爆音问题

1. 移除 server.js 生成的每个音频分片携带的 44 字节 WAV 头,防止将其作为音频样本解码导致每 0.25 秒出现点击声 ('哒')。 2. 优化 playAudio 队列满时的轮询机制,从原先阻塞等待 speaker_audio_empty(会导致扬声器饥饿)改为使用 0.05 秒的定时器定期尝试,以保持缓冲区处于满载状态。 3. 同步修复了 station_broadcast-warning.lua 中潜在的相同轮询饥饿问题。 4. 版本号递增至 v1.0.62。
This commit is contained in:
2026-08-16 11:32:00 +08:00
parent 6b1a531b77
commit 298308b7f3
3 changed files with 162 additions and 18 deletions
+19 -2
View File
@@ -1,3 +1,4 @@
-- Random Audio Player
-- Simplified version that only plays random audio files
@@ -45,7 +46,15 @@ local function playDfpwmFile(path, volume)
if controller and type(controller.playAudioAll) == "function" then
while not controller.playAudioAll(samples, volume) do
os.pullEvent("speaker_audio_empty")
local timerId = os.startTimer(0.05)
while true do
local ev = { os.pullEvent() }
if ev[1] == "timer" and ev[2] == timerId then
break
elseif ev[1] == "speaker_audio_empty" then
break
end
end
end
else
local pending = {}
@@ -59,7 +68,15 @@ local function playDfpwmFile(path, volume)
end
end
if next(pending) then
os.pullEvent("speaker_audio_empty")
local timerId = os.startTimer(0.05)
while true do
local ev = { os.pullEvent() }
if ev[1] == "timer" and ev[2] == timerId then
break
elseif ev[1] == "speaker_audio_empty" then
break
end
end
end
end
end