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:
1 parent
2717292366
commit
9466c5f471
7 files changed
+96
-13
No files matched your search
@@ -242,9 +242,10 @@ def write_xm(title, instruments, orders, patterns, channels, speed=6, tempo=125,
|
||||
ls, ll, lt = s.get("loop") or (0, 0, 0)
|
||||
t = lt | (16 if bpsm == 2 else 0)
|
||||
out += struct.pack("<IIIBbBBbB", len(s["data"]), ls * bpsm, ll * bpsm, s.get("volume", 64), s.get("finetune", 0),
|
||||
t, s.get("pan", 128), s.get("relnote", 0), 0) + name(s.get("name", ""), 22)
|
||||
t, s.get("pan", 128), s.get("relnote", 0), 0xAD if s.get("adpcm") else 0) + name(s.get("name", ""), 22)
|
||||
for s in smps:
|
||||
out += delta16(s["data"]) if s.get("bits", 8) == 16 else delta8(s["data"])
|
||||
# "adpcm": ModPlug ADPCM bytes (16-byte delta table + nibbles) stored instead of the delta samples
|
||||
out += s["adpcm"] if s.get("adpcm") else delta16(s["data"]) if s.get("bits", 8) == 16 else delta8(s["data"])
|
||||
return bytes(out)
|
||||
|
||||
|
||||
|
||||
+30
-1
@@ -159,9 +159,38 @@ def song_effects(linear=True):
|
||||
return T.write_xm("effects", instruments(), [0, 1], [a, b], 6, speed=5, tempo=130, linear=linear, restart=1)
|
||||
|
||||
|
||||
TABLE = [0, 1, 2, 4, 8, 16, 32, 64, -1, -2, -4, -8, -16, -32, -64, -128]
|
||||
|
||||
|
||||
def modplug_adpcm(raw):
|
||||
"""ModPlug ADPCM of 8-bit sample bytes: the delta table, then one nibble per sample (low first), each nibble the
|
||||
table delta that lands nearest (the running value wraps as a signed byte)"""
|
||||
cur, nibs = 0, []
|
||||
for b in raw:
|
||||
want = b - 256 if b >= 128 else b
|
||||
best = min(range(16), key=lambda k: abs(((cur + TABLE[k] + 128) % 256 - 128) - want))
|
||||
cur = (cur + TABLE[best] + 128) % 256 - 128
|
||||
nibs.append(best)
|
||||
if len(nibs) % 2:
|
||||
nibs.append(0)
|
||||
return bytes(t & 255 for t in TABLE) + bytes(nibs[i] | nibs[i + 1] << 4 for i in range(0, len(nibs), 2))
|
||||
|
||||
|
||||
def song_adpcm():
|
||||
"""a ModPlug ADPCM sample (OpenMPT's compressed 8-bit samples) played at a few pitches"""
|
||||
raw = T.s8(T.synth("saw", 400, 100, 0.6))
|
||||
smp = {"name": "adpcm", "data": raw, "adpcm": modplug_adpcm(raw), "volume": 64, "pan": 128, "loop": (0, 400, 1)}
|
||||
p = empty(2)
|
||||
for i, note in enumerate((49, 53, 56, 61)):
|
||||
put(p, i * 8, 0, note, 1)
|
||||
put(p, i * 8 + 4, 1, note - 12, 1)
|
||||
return T.write_xm("adpcm", [{"name": "adpcm", "samples": [smp]}], [0], [p], 2, speed=4, tempo=125)
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
cases = []
|
||||
for nm, data in (("instruments", song_instruments()), ("effects", song_effects()), ("amiga", song_effects(False))):
|
||||
for nm, data in (("instruments", song_instruments()), ("effects", song_effects()), ("amiga", song_effects(False)),
|
||||
("adpcm", song_adpcm())):
|
||||
ref = T.reference(ctx, data, "xm")
|
||||
cases.append({"name": nm, "data": data, "ref": ref, "duration": ref["duration"]})
|
||||
ctx.emit("xm_cases", cases)
|
||||
Reference in new issue
Block a user