fix(switch): pass NX cache prefix to the chip-audio worker

Yellow music was still silent because the background worker thread loads
ChipSynth.lua in a fresh Lua state with no GameVersion/Platform context.
The main thread's prefix never reached it.

ChipAudio.slimAudio now resolves the versioned cache prefix on the main
thread and includes it in the audio payload as `programPrefix`.
ChipSynth.loadBanks prefers `audio.programPrefix` when present, falling
back to its own NX detection for the sync path. Blue and Yellow are
handled the same way.

Tests cover the worker prefix hand-off and Blue's programs.bin path.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Andrew Quenehen
2026-08-03 15:26:37 -03:00
parent e4ce1063a1
commit 16b6b98ede
3 changed files with 59 additions and 7 deletions
+13
View File
@@ -100,14 +100,27 @@ end
-- play so a hot-reloaded dataset (or a mod's audio) always reaches the worker
local function slimAudio(data)
local audio = data.audio or {}
-- NX-only: resolve the versioned cache prefix on the main thread and hand
-- it to the worker, which runs in a fresh Lua state without GameVersion.
local programPrefix
if require("src.core.Platform").isNX() then
local prefix = require("src.core.GameVersion").cachePrefix()
if prefix ~= "" then programPrefix = prefix end
end
return {
programFile = audio.programFile,
programPrefix = programPrefix,
bankOrder = audio.bankOrder,
waveBanks = audio.waveBanks,
noiseHeaders = audio.noiseHeaders,
}
end
-- test-only: expose slimAudio so the NX prefix hand-off is verifiable
function ChipAudio._slimAudioForTest(data)
return slimAudio(data)
end
-- If the worker died (a malformed def that errors mid-synth), fall back to the
-- synchronous path for the rest of the session instead of going silent.
local function workerAlive()
+10 -7
View File
@@ -124,13 +124,16 @@ local function loadBanks(data)
return cachedBanks
end
local raw, readError
-- NX-only: Blue/Yellow live under a versioned save-dir prefix; desktop
-- relies on mountVersion overlay. Read the prefixed path when present.
if require("src.core.Platform").isNX() then
local prefix = require("src.core.GameVersion").cachePrefix()
if prefix ~= "" then
raw, readError = love.filesystem.read(prefix .. audio.programFile)
end
-- NX-only: Blue/Yellow live under a versioned save-dir prefix. The main
-- thread resolves it before sending audio to the worker; the sync path
-- resolves it here so desktop keeps the mountVersion overlay behavior.
local prefix = audio.programPrefix
if not prefix and require("src.core.Platform").isNX() then
local gv = require("src.core.GameVersion").cachePrefix()
if gv ~= "" then prefix = gv end
end
if prefix and prefix ~= "" then
raw, readError = love.filesystem.read(prefix .. audio.programFile)
end
if not raw then
raw, readError = love.filesystem.read(audio.programFile)