# Nintendo stream fixtures (tools/fixtures.py): audio/brstm. Our Python writer and DSP encoder (tools/fixtures/_adpcm.py) # build BRSTM / BCSTM / BFSTM files (DSP ADPCM with a filled ADPC / SEEK history table, PCM16, PCM8; several blocks # with a short padded last block; loops); vgmstream decodes them and reports the loops. # tests/gen/brstm_cases.luau { name, data, rate, ch, ref (s16le), loopStart?, loopEnd? } import importlib.util, os, re _dir = os.path.dirname(os.path.abspath(__file__)) def _load(name): spec = importlib.util.spec_from_file_location(name, os.path.join(_dir, name + ".py")) m = importlib.util.module_from_spec(spec) spec.loader.exec_module(m) return m A = _load("_audio") D = _load("_adpcm") INPUTS = ["tools/fixtures/_adpcm.py", "src/Rosetta/codecs/audio/Adpcm", "src/Rosetta/audio/brstm"] def generate(ctx): stereo = A.signal("music", 32000, 2, 9000, seed=31) mono = A.signal("sweep", 22050, 1, 8000, seed=32) made = [ ("rstm-dsp-stereo", "RSTM", stereo, 32000, 2, dict(block=0x800)), ("rstm-dsp-mono-loop", "RSTM", mono, 22050, 1, dict(block=0x400, loop=(1000, 8000))), ("rstm-pcm16-stereo", "RSTM", stereo, 32000, 2, dict(block=0x2000, codec="pcm16")), ("cstm-dsp-stereo-loop", "CSTM", stereo, 32000, 2, dict(block=0x800, loop=(4000, 9000))), ("cstm-pcm8-mono", "CSTM", mono, 22050, 1, dict(block=0x1000, codec="pcm8")), ("fstm-be-dsp-stereo", "FSTM", stereo, 32000, 2, dict(block=0x1000)), ("fstm-le-dsp-mono", "FSTM", mono, 22050, 1, dict(block=0x800, le=True)), ("fstm-le-pcm16-stereo", "FSTM", stereo, 32000, 2, dict(block=0x1000, le=True, codec="pcm16")), ] cases = [] for name, kind, sig, rate, ch, kw in made: data = D.rstm(sig, rate, ch, kind, **kw) ext = {"RSTM": "brstm", "CSTM": "bcstm", "FSTM": "bfstm"}[kind] r, c, ref = D.vgdecode(ctx, data, ext) assert (r, c) == (rate, ch) and len(ref) == len(sig) * 2, (name, r, c, len(ref)) e = dict(name=name, data=data, rate=rate, ch=ch, ref=ref) m = re.search(r"loop start: (\d+) samples.*?loop end: (\d+) samples", D.vginfo(ctx, data, ext), re.S) if m: e["loopStart"], e["loopEnd"] = int(m.group(1)), int(m.group(2)) cases.append(e) ctx.emit("brstm_cases", cases)