From 0a7b74ec49a7f1ec866fc1706f6ff589b54eaf1f Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sat, 31 Oct 2026 14:58:37 -0500 Subject: [PATCH] ws-audio2: docs/guide/music.md: the other tracker formats (table rows, Module.engine, More tracker formats with tested snippets; docs_av inputs mtm / med / umx); bench: render 669 / med --- docs/guide/music.md | 51 +++++++++++++++++++++++++++++++++++++-- tools/bench.luau | 26 ++++++++++++++++++++ tools/fixtures/docs_av.py | 15 +++++++++--- 3 files changed, 87 insertions(+), 5 deletions(-) diff --git a/docs/guide/music.md b/docs/guide/music.md index 369929d..b156c9f 100644 --- a/docs/guide/music.md +++ b/docs/guide/music.md @@ -1,6 +1,7 @@ # Music -Music files hold notes and instruments, not a recording. Tracker modules (MOD, S3M, XM, IT) load as a **Module**: +Music files hold notes and instruments, not a recording. Tracker modules (MOD, S3M, XM, IT, and the +[other trackers](#more-tracker-formats): MTM, 669, STM, ULT, OKT, MED, PTM, FAR, UMX) load as a **Module**: the patterns, the order list, the samples and the instruments. Standard MIDI files load as a **Midi**: tracks of timed events. Both render to the standard audio [Decoder](audio.md#decoder), so every music file can also be played, analysed or saved as audio. MIDI renders through a SoundFont 2 bank, or through a small built-in set of @@ -26,7 +27,8 @@ assert(audio.channels == 2 and audio.sampleRate == 44100) | Field | Type | Meaning | |---|---|---| | `kind` | `"music"` | | -| `format` | string | `"mod"`, `"s3m"`, `"xm"` or `"it"`: the effect family the engine plays | +| `format` | string | the format it was read from: `"mod"`, `"s3m"`, `"xm"`, `"it"`, `"mtm"`, `"669"`, `"med"`, ... | +| `engine` | string? | the effect family the engine plays (`"mod"`, `"s3m"`, `"xm"`, `"it"`); absent: the same as `format`. Set by the [other trackers](#more-tracker-formats) | | `title` | string | | | `channels` | number | pattern channels | | `speed`, `tempo` | number | initial ticks per row, and BPM (a tick lasts `2.5 / tempo` seconds) | @@ -312,9 +314,52 @@ assert(F.music.load(assert(F.save(xm))).instruments[1].name == "lead") | s3m, it | yes | - | Module | | midi (.mid, .kar, RMID) | yes | yes (SMF) | Midi | | sf2 | yes | - | SoundFont | +| mtm (MultiTracker) | yes | - | Module (xm family) | +| 669 (Composer 669, UNIS 669) | yes | - | Module (s3m family) | +| stm (Scream Tracker 2) | yes | - | Module (s3m family) | +| ult (UltraTracker) | yes | - | Module (it family) | +| okt (Oktalyzer) | yes | - | Module (it family) | +| med (MED / OctaMED MMD0..MMD3) | yes | - | Module (xm family) | +| ptm (PolyTracker) | yes | - | Module (it family) | +| far (Farandole Composer) | yes | - | Module (s3m family) | +| umx (Unreal package) | yes | - | the embedded IT / S3M / XM / MOD Module | See [FORMATS.md](../FORMATS.md) for each format's capabilities. +### More tracker formats + +MultiTracker, Composer 669, Scream Tracker 2, UltraTracker, Oktalyzer, MED / OctaMED, PolyTracker and Farandole +modules load as Modules too (ported from OpenMPT's loaders). Each keeps its own `format` name and plays through one of +the four effect families (`engine`), with the format's quirks in `flags`: 669 and Farandole slide in Hz, Scream +Tracker 2 has its own tempo byte, MED its tempo modes and hold / decay, Oktalyzer its mixed channel pairs. Their +cells use the family's effect coding (an MTM cell reads like an XM cell, an OKT cell like an IT cell); a few effects +of these formats have no family equivalent and use the engine's extension codes (0x40 and up: note slides, auto +portamentos, ...). + +```luau +local song = assert(F.music.load(mtmBytes)) +assert(song.format == "mtm" and song.engine == "xm" and song.channels == 6) +local med = assert(F.music.load(medBytes)) +assert(med.format == "med" and med.meta.source.version == "MMD1" and med.instrumentMode) -- hold / decay: instruments +local audio = assert(F.ops.audio.toAudio(med:render({ sampleRate = 22050 }))) +assert(audio.frames > 0) +``` + +An Unreal `.umx` package holds a module (usually IT, S3M or XM). `F.load` unwraps it and returns that module, with +the package in `meta.container`; `F.format("umx").extract` lists the embedded modules without loading them. + +```luau +local m = assert(F.music.load(umxBytes)) +assert(m.format == "s3m" and m.meta.container.format == "umx" and m.meta.container.name == "theme") +local list = assert(F.format("umx").extract(F.Bytes.reader(umxBytes))) +assert(#list == 1 and list[1].format == "s3m") +local dec = assert(F.open(umxBytes)) -- rendered, like any module +assert(dec.channels == 2) +``` + +These formats are read only. Their Modules render to audio like any other (`F.save(song, nil, { format = "wav" })`), +and the module of an UMX keeps its own format, so `F.save(m)` works when that format has a writer (MOD, XM). + ## Gotchas - Saving music to an audio format renders it with the options in `opts`: `F.save(song, nil, { format = "wav", @@ -325,4 +370,6 @@ See [FORMATS.md](../FORMATS.md) for each format's capabilities. - Without a SoundFont, MIDI plays on simple built-in waveforms, which is fine for testing but not General MIDI. SF3 banks (Ogg-compressed samples) are not supported. - Pattern cells keep the file's own effect numbering, which differs between MOD / XM (0..35) and S3M / IT (1..26). + The other tracker formats use their engine family's numbering (`m.engine`), not their file's. +- A Module's `meta.unsupported` lists what was read but plays silent (MED synth / hybrid / MIDI instruments). - A module's `duration` is one pass. `render({ loop = true })` keeps playing past it. diff --git a/tools/bench.luau b/tools/bench.luau index b32ee01..d2af7b0 100644 --- a/tools/bench.luau +++ b/tools/bench.luau @@ -1078,3 +1078,29 @@ do jitTune(false) end end +-- ws-audio2: trackers +do + -- the other tracker loaders on the shared engine: a 669 (Hz periods, auto slides) and an MMD1 (hold / decay + -- envelopes, instruments) from tools/fixtures/{669,med}.py, decoded and rendered at 44.1 kHz + local Six69 = require("@formats/music/669") + local Med = require("@formats/music/med") + local songs = { { Six69, require("@tests/gen/669_cases")[1].data }, { Med, require("@tests/gen/med_cases")[2].data } } + local best, frames = math.huge, 0 + local out = buffer.create(4096 * 8) + for _ = 1, 3 do + frames = 0 + local t0 = os.clock() + for _, s in songs do + local dec = (s[1].decode(Bytes.reader(buffer.fromstring(s[2]))) :: any):render() + while true do + local _, n = dec:read(4096, out) + if n == 0 then + break + end + frames += n + end + end + best = math.min(best, os.clock() - t0) + end + print(string.format("%-8s %-30s %8.2f ms %7.1f x realtime", runtime, "render 669 / med", best * 1000, frames / 44100 / best)) +end diff --git a/tools/fixtures/docs_av.py b/tools/fixtures/docs_av.py index 8019408..dc4c004 100644 --- a/tools/fixtures/docs_av.py +++ b/tools/fixtures/docs_av.py @@ -1,12 +1,13 @@ # Docs inputs for the audio / music / video / subtitle guide pages (tools/fixtures.py; tools/docs_check.py reads them): # tiny ffmpeg test clips (testsrc 64x48, 10 frames at 10 fps, with a sine track): MP4 (H.264 + AAC), AVI (MJPEG + # PCM), WebM (VP8 + Vorbis); a MIDI file written here (SMF 1: a tempo track and a melody), the SoundFont of -# tools/fixtures/sf2.py (build_sf2), a ProTracker module from tools/fixtures/mod.py (song_basic), and SRT / WebVTT / -# ASS subtitles. +# tools/fixtures/sf2.py (build_sf2), a ProTracker module from tools/fixtures/mod.py (song_basic), MultiTracker / MED +# modules and an Unreal package (tools/fixtures/mtm.py, med.py, s3m.py), and SRT / WebVTT / ASS subtitles. # tests/gen/docs_av.luau { files = { [name] = bytes }, vars = { mp4Bytes = "clip.mp4", ... } } import importlib.util, os, struct, tempfile -INPUTS = ["tools/docs_check.py", "tools/fixtures/sf2.py", "tools/fixtures/mod.py"] +INPUTS = ["tools/docs_check.py", "tools/fixtures/sf2.py", "tools/fixtures/mod.py", "tools/fixtures/mtm.py", + "tools/fixtures/med.py", "tools/fixtures/s3m.py", "tools/fixtures/_tracker.py"] def load(ctx, name): @@ -100,6 +101,11 @@ def generate(ctx): files["bank.sf2"] = sf2.build_sf2(False)[0] mod = load(ctx, "fixtures/mod") files["song.mod"] = mod.song_basic() + # ws-audio2: more tracker formats (tools/fixtures/mtm.py, med.py; an Unreal package around an S3M) + files["song.mtm"] = load(ctx, "fixtures/mtm").song_effects() + files["song.med"] = load(ctx, "fixtures/med").song_basic(version=1) + tracker = load(ctx, "fixtures/_tracker") + files["music.umx"] = tracker.write_umx([("Theme", load(ctx, "fixtures/s3m").song_mono())]) files["subs.srt"] = SRT files["subs.vtt"] = VTT files["subs.ass"] = ASS @@ -110,6 +116,9 @@ def generate(ctx): "midiBytes": "tune.mid", "sf2Bytes": "bank.sf2", "modBytes": "song.mod", + "mtmBytes": "song.mtm", + "medBytes": "song.med", + "umxBytes": "music.umx", "srtText": "subs.srt", "vttText": "subs.vtt", "assText": "subs.ass",