fix(audio): prebuffer live wav stream startup
Buffer a couple of live wav chunks before beginning playback so startup jitter is reduced when the stream first begins feeding speakers.
This commit is contained in:
+28
-1
@@ -2,7 +2,7 @@
|
|||||||
-- ============================================================================
|
-- ============================================================================
|
||||||
-- 1. Configuration & Constants
|
-- 1. Configuration & Constants
|
||||||
-- ============================================================================
|
-- ============================================================================
|
||||||
local APP_VERSION_TEXT = "v1.0.13"
|
local APP_VERSION_TEXT = "v1.0.14"
|
||||||
|
|
||||||
local CONFIG = {
|
local CONFIG = {
|
||||||
CLOUD_URL = "ws://stabadmin.fse-media.group",
|
CLOUD_URL = "ws://stabadmin.fse-media.group",
|
||||||
@@ -14,6 +14,7 @@ local CONFIG = {
|
|||||||
DISK_AUDIO_STATION = "disk/Audio/Station/",
|
DISK_AUDIO_STATION = "disk/Audio/Station/",
|
||||||
STATION_IDENTITY_FILE = "station_identity.cfg",
|
STATION_IDENTITY_FILE = "station_identity.cfg",
|
||||||
AUDIO_VOLUME = 3,
|
AUDIO_VOLUME = 3,
|
||||||
|
AUDIO_STREAM_PREROLL_CHUNKS = 2,
|
||||||
DEBUG = true
|
DEBUG = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -739,6 +740,14 @@ function Audio.createStream()
|
|||||||
end
|
end
|
||||||
return table.remove(chunks, 1)
|
return table.remove(chunks, 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
stream.count = function()
|
||||||
|
return #chunks
|
||||||
|
end
|
||||||
|
|
||||||
|
stream.isFinished = function()
|
||||||
|
return finished
|
||||||
|
end
|
||||||
|
|
||||||
return stream
|
return stream
|
||||||
end
|
end
|
||||||
@@ -1393,8 +1402,10 @@ function Audio.playWavStreamItem(item)
|
|||||||
|
|
||||||
local playSeq = State.interruptSeq
|
local playSeq = State.interruptSeq
|
||||||
local source = item.audioData
|
local source = item.audioData
|
||||||
|
local streamObj = nil
|
||||||
|
|
||||||
if type(source) == "table" and source.read then
|
if type(source) == "table" and source.read then
|
||||||
|
streamObj = source
|
||||||
source = source.read
|
source = source.read
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1407,6 +1418,22 @@ function Audio.playWavStreamItem(item)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local prebufferChunks = math.max(0, tonumber(CONFIG.AUDIO_STREAM_PREROLL_CHUNKS) or 0)
|
||||||
|
if streamObj and prebufferChunks > 0 then
|
||||||
|
Utils.log("INFO", "Prebuffering live WAV stream: target chunks=" .. tostring(prebufferChunks))
|
||||||
|
while streamObj.count() < prebufferChunks and not streamObj.isFinished() do
|
||||||
|
if shouldStop(playSeq) then
|
||||||
|
Audio.stop("current")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if not waitForInterruptibleDelay(playSeq, 0.02) then
|
||||||
|
Audio.stop("current")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Utils.log("INFO", "Live WAV prebuffer ready: chunks=" .. tostring(streamObj.count()))
|
||||||
|
end
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
if shouldStop(playSeq) then
|
if shouldStop(playSeq) then
|
||||||
Audio.stop("current")
|
Audio.stop("current")
|
||||||
|
|||||||
Reference in New Issue
Block a user