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

This commit is contained in:
4DBug committed 2026-10-31 14:58:37 -05:00
1 parent 26fa887370
commit 0a7b74ec49
3 files changed
+87 -5

No files matched your search

+49 -2
View File
@@ -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.