ws-audio2: audio/adx (CRI ADX read / write, loops) and audio/vag (VAGp / VAGi / KVAG read, VAGp / VAGi write)

Bit-exact with vgmstream (ADX, PS-ADPCM) and ffmpeg (KVAG IMA); ADX and PS-ADPCM encoders in codecs/audio/Adpcm.
This commit is contained in:
4DBug committed 2026-10-31 14:17:57 -05:00
1 parent 363b14932f
commit fd9175883d
10 files changed
+987 -1

No files matched your search

+13 -1
View File
@@ -316,7 +316,7 @@ def wav_pcm(data):
def vgdecode(ctx, data, ext):
"""vgmstream's decode of a file: (rate, channels, s16le bytes); loop facts come from vgminfo"""
A = _audio()
out = A.tool(ctx, "vgmstream", ["vgmstream-cli", "-o", "{out}", "{in}"], data, ext, outext="wav")
out = A.tool(ctx, "vgmstream", ["vgmstream-cli", "-i", "-o", "{out}", "{in}"], data, ext, outext="wav")
return wav_pcm(out)
@@ -350,3 +350,15 @@ def _audio():
_A = importlib.util.module_from_spec(spec)
spec.loader.exec_module(_A)
return _A
def vagi(samples, rate, ch=2, interleave=0x400):
"""a VAGi file (stereo PS-ADPCM, channels interleaved every `interleave` bytes, data at 0x800)"""
ints = s16(samples)
chans = [psx_encode(ints[c::ch]) for c in range(ch)]
size = max(len(x) for x in chans)
size = (size + interleave - 1) // interleave * interleave
chans = [x.ljust(size, b"\0") for x in chans]
data = b"".join(chans[c][k:k + interleave] for k in range(0, size, interleave) for c in range(ch))
head = b"VAGi" + struct.pack(">I", 0x20) + struct.pack("<I", interleave) + struct.pack(">II", size, rate)
return head.ljust(0x800, b"\0") + data