ws-audio2: music/xm decodes ModPlug ADPCM samples (were silence), through codecs/audio/Adpcm.modplug

Fixture: tools/fixtures/_tracker.py write_xm gains an optional per-sample "adpcm" payload (two lines, shared with
the tracker generators, backward compatible); a new xm case renders the same as openmpt123.
This commit is contained in:
4DBug committed 2026-10-31 14:37:23 -05:00
1 parent 2717292366
commit 9466c5f471
7 files changed
+96 -13

No files matched your search

+19
View File
@@ -19,6 +19,7 @@
-- Adpcm.adxCoefs(cutoff, rate) -> c1, c2
-- Adpcm.psx(src, p, pstride, nframes, st, so, dst, d, ds) -- Sony PS-ADPCM (VAG): 16-byte frames, 28 samples
-- Adpcm.dsp(src, p, count, coefs, co, st, so, dst, d, ds) -- Nintendo DSP: 8-byte frames, 14 samples
-- Adpcm.modplug(src, p, count, dst, d) -- ModPlug ADPCM (XM / MOD samples)
-- encoders: imaEncode, imaWavEncode, msEncode, adxEncode, psxEncode, dspEncode (see each)
--
-- Every function reads only the bytes its arguments describe: the caller checks the ranges (byte counts per call are
@@ -685,4 +686,22 @@ function Adpcm.psxEncode(x: buffer, xi: number, xs: number, count: number, st: b
writei32(st, so + 4, h2)
end
-- ------------------------------------------------------------------------------------------------ ModPlug
-- modplug: ModPlug / OpenMPT ADPCM samples (XM / MOD sample data marked 0xAD): a table of 16 signed byte deltas at
-- p, then count nibbles (low first) at p + 16, each adding its table delta to a running signed byte (wrapping).
-- Writes count f32 (value / 128) to dst from float index d. Reads p .. p + 16 + ceil(count / 2) - 1.
function Adpcm.modplug(src: buffer, p: number, count: number, dst: buffer, d: number)
local tab = table.create(16, 0)
for k = 0, 15 do
tab[k + 1] = buffer.readi8(src, p + k)
end
local v = 0
for i = 0, count - 1 do
local b = readu8(src, p + 16 + rshift(i, 1))
local nib = if band(i, 1) == 0 then band(b, 15) else rshift(b, 4)
v = (v + tab[nib + 1] + 128) % 256 - 128
writef32(dst, (d + i) * 4, v / 128)
end
end
return Adpcm