From 6c3a4ad358ebbf1c7b530cb72cfc2a04ea85f368 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sat, 31 Oct 2026 09:32:09 -0500 Subject: [PATCH] ws-music: tracker seek / loop tests --- tests/music/mod.luau | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/music/mod.luau b/tests/music/mod.luau index 84500de..5dc59fa 100644 --- a/tests/music/mod.luau +++ b/tests/music/mod.luau @@ -84,6 +84,28 @@ do local _, n = dec:read(1000) t:eq(n, 1000, "read after seek") t:check(Tracker.duration(m) == dec.duration, "duration()") + -- the same samples as playing up to that point (after the short fade-in that follows a seek) + local a, b = m:render(), m:render() + a:seek(3.5) + local at = math.floor(3.5 * S.SR) + while at > 0 do + local _, n = b:read(math.min(at, 8192)) + at -= n + end + local x, y = a:read(4096), b:read(4096) + local worst = 0 + for i = 256, 4095 * 2 do + worst = math.max(worst, math.abs(buffer.readf32(x, i * 4) - buffer.readf32(y, i * 4))) + end + t:check(worst < 1e-4, "seek then read matches reading through (" .. worst .. ")") + -- loop = true keeps playing past the end (frames / duration still give one pass) + local l = m:render({ loop = true, sampleRate = 8000 }) + local total = 0 + for _ = 1, 30 do + local _, n = l:read(8000) + total += n + end + t:check(total == 240000 and l.duration == dec.duration, "loop plays past the end") end -- the fuzz pass: decode, and a short render of whatever decodes