From e7421a8829234e17f99e442eceb6124df51db35a Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:52:44 -0500 Subject: [PATCH] music formats: comments are specs only --- src/Rosetta/music/669/init.luau | 17 ++++++----------- src/Rosetta/music/ahx/init.luau | 12 ++++-------- src/Rosetta/music/far/init.luau | 15 +++++---------- src/Rosetta/music/hmp/init.luau | 21 +++++---------------- src/Rosetta/music/hvl/init.luau | 12 ++++-------- src/Rosetta/music/it/Itsex.luau | 10 ++-------- src/Rosetta/music/it/init.luau | 19 ++++--------------- src/Rosetta/music/med/init.luau | 30 +++++++----------------------- src/Rosetta/music/midi/Smf.luau | 15 +++------------ src/Rosetta/music/midi/init.luau | 25 ++++++------------------- src/Rosetta/music/mod/init.luau | 22 ++++++---------------- src/Rosetta/music/mtm/init.luau | 14 ++++---------- src/Rosetta/music/mus/init.luau | 14 +++----------- src/Rosetta/music/okt/init.luau | 15 ++++----------- src/Rosetta/music/ptm/init.luau | 15 ++++----------- src/Rosetta/music/s3m/init.luau | 16 ++++------------ src/Rosetta/music/sf2/init.luau | 9 +++------ src/Rosetta/music/stm/init.luau | 12 ++++-------- src/Rosetta/music/ult/init.luau | 21 +++++++-------------- src/Rosetta/music/umx/init.luau | 18 +++++------------- src/Rosetta/music/xm/init.luau | 26 ++++++-------------------- src/Rosetta/music/xmi/init.luau | 15 +++------------ 22 files changed, 99 insertions(+), 274 deletions(-) diff --git a/src/Rosetta/music/669/init.luau b/src/Rosetta/music/669/init.luau index ab4e70e..50d14d0 100644 --- a/src/Rosetta/music/669/init.luau +++ b/src/Rosetta/music/669/init.luau @@ -1,11 +1,7 @@ --!strict --- music/669: Composer 669 and UNIS 669 modules ("if" / "JN"; 8 channels, 64-row patterns with their own speed and --- break row). Ported from OpenMPT's Load_669.cpp (BSD, licenses/openmpt-LICENSE.txt). Reads into the --- codecs/audio/Tracker Module and plays as the "s3m" effect family with 669's quirks (flags): periods in Hz (slides --- move the frequency 80 Hz per step, tone portamento 40 Hz), slides on every tick, auto portamentos that run until --- the channel's next effect, a tone portamento that keeps going, frequency adjust (D), frequency vibrato (E), speed (F), --- UNIS 669 balance slides (G) and slot retrigger (H). The tempo is fixed (78 BPM in tracker terms). --- Not supported: UNIS 669's "super fast" speed 0, writing. +-- music/669: Composer 669 / UNIS 669 modules ("if" / "JN"), ported from OpenMPT's Load_669.cpp (BSD, +-- licenses/openmpt-LICENSE.txt). Supports: 8 channels, 64-row patterns, played as the "s3m" family with 669's quirks +-- (periods in Hz, auto portamentos, effects D..H, a fixed 78 BPM). Not supported: UNIS 669's speed 0, writing. -- ------------------------------------------------------------------------------------------------ requires local Err = require("@rosetta/core/Err") @@ -25,16 +21,16 @@ local Six69 = { } export type DecodeOptions = { - maxBytes: number?, -- refuse more sample data in total (f32 bytes, default 2^28) + maxBytes: number?, -- f32 bytes of sample data in total, default 2^28 } -- ------------------------------------------------------------------------------------------------ constants local IT = Load.IT --- the 669 effects (high nibble of the effect byte) by name +-- effects: the high nibble of the effect byte local EFFECTS = { "autoportaup", "autoportadown", "toneporta", "freqadjust", "vibrato", "speed", "panslide", "retrig" } -- ------------------------------------------------------------------------------------------------ sniff --- the 497-byte header is valid (669 has a two-byte magic only, so the rest is checked too) +-- the 497-byte header (the magic is two bytes only, so the other fields are checked too) local function validHeader(r: Bytes.Reader): boolean if r:size() < 497 then return false @@ -197,7 +193,6 @@ function Six69.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) end -- ------------------------------------------------------------------------------------------------ open --- open(r, opts) -> the module rendered as an audio Decoder (opts: Tracker.RenderOptions + DecodeOptions) function Six69.open(r: Bytes.Reader, opts: any?): (Types.Decoder?, Err.Err?) local m, err = Six69.decode(r, opts) if not m then diff --git a/src/Rosetta/music/ahx/init.luau b/src/Rosetta/music/ahx/init.luau index c888acf..eee4cd5 100644 --- a/src/Rosetta/music/ahx/init.luau +++ b/src/Rosetta/music/ahx/init.luau @@ -1,10 +1,7 @@ --!strict --- music/ahx: AHX (Abyss' Highest eXperience) modules, "THX\0" .. "THX\2": 4-channel Amiga synth tunes (no samples: --- triangle / sawtooth / square / noise waveforms through filters, square modulation, the PList instrument programs). --- Loads into a Types.Module-shaped value (kind "music", format "ahx": tracks as patterns, positions with per-channel --- transposes, instruments with play lists, subsongs) and renders through codecs/audio/Hively, a port of HivelyTracker's --- hvl2wav replayer (BSD-3-Clause): at 44.1 kHz with stereo = 0 the samples equal hvl2wav's. --- Not supported: writing. +-- music/ahx: AHX (Abyss' Highest eXperience) 4-channel Amiga synth modules, "THX\0" .. "THX\2", rendered through +-- codecs/audio/Hively (a port of HivelyTracker's hvl2wav, BSD-3-Clause; at 44.1 kHz, stereo 0, equal to hvl2wav). +-- Supports: tracks, positions with transposes, PList instruments, subsongs. Not supported: writing. -- ------------------------------------------------------------------------------------------------ requires local Err = require("@rosetta/core/Err") @@ -23,7 +20,7 @@ local Ahx = { } -- ------------------------------------------------------------------------------------------------ types -export type RenderOptions = Hively.RenderOptions -- sampleRate, subsong, stereo (0..4), loop, maxDuration +export type RenderOptions = Hively.RenderOptions -- stereo 0..4 -- ------------------------------------------------------------------------------------------------ sniff function Ahx.sniff(r: Bytes.Reader): number @@ -41,7 +38,6 @@ function Ahx.decode(r: Bytes.Reader, _opts: any?): (Types.Module?, Err.Err?) end -- ------------------------------------------------------------------------------------------------ open --- open(r, opts?) -> the rendered audio Decoder (opts: RenderOptions) function Ahx.open(r: Bytes.Reader, opts: RenderOptions?): (Types.Decoder?, Err.Err?) local song, err = Ahx.decode(r) if not song then diff --git a/src/Rosetta/music/far/init.luau b/src/Rosetta/music/far/init.luau index 20861d7..c5ac494 100644 --- a/src/Rosetta/music/far/init.luau +++ b/src/Rosetta/music/far/init.luau @@ -1,11 +1,7 @@ --!strict --- music/far: Farandole Composer modules (FAR, Daniel Potter's DOS tracker; 16 channels, up to 256 patterns of any --- length with a break row, 64 samples). Ported from OpenMPT's Load_far.cpp (BSD, licenses/openmpt-LICENSE.txt). Reads --- into the codecs/audio/Tracker Module and plays as the "s3m" effect family with Farandole's quirks (flags): periods --- in Hz (a slide step moves the frequency 36318 / 1024 Hz), a tone portamento that keeps going, fine pitch slides, --- retrigger, vibrato depth / speed, volume slides, volume portamento (as a set volume), panning, speed; the fixed --- tempo OpenMPT uses (80 BPM in tracker terms). --- Not supported: Farandole's own tempo model (fine tempo up / down, D / E), the note-offset effect (C), writing. +-- music/far: Farandole Composer modules (FAR, 16 channels), ported from OpenMPT's Load_far.cpp (BSD, +-- licenses/openmpt-LICENSE.txt). Plays as the "s3m" family with FAR's quirks (periods in Hz, a slide step of +-- 36318 / 1024 Hz, OpenMPT's fixed 80 BPM). Not supported: FAR's tempo effects (D / E), note offset (C), writing. -- ------------------------------------------------------------------------------------------------ requires local Err = require("@rosetta/core/Err") @@ -25,7 +21,7 @@ local Far = { } export type DecodeOptions = { - maxBytes: number?, -- refuse more sample data in total (f32 bytes, default 2^28) + maxBytes: number?, -- f32 bytes of sample data in total, default 2^28 } -- ------------------------------------------------------------------------------------------------ constants @@ -40,7 +36,7 @@ function Far.sniff(r: Bytes.Reader): number end -- ------------------------------------------------------------------------------------------------ decode --- a pattern cell's effect byte -> effect code, parameter, volume byte (S3M coding, 0 = none) (OpenMPT's table) +-- effect byte -> S3M effect, parameter, volume byte (0 = none): OpenMPT's table local function effect(e: number): (number, number, number) local cmd, p = e // 16, e % 16 if cmd == 1 then @@ -220,7 +216,6 @@ function Far.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) end -- ------------------------------------------------------------------------------------------------ open --- open(r, opts) -> the module rendered as an audio Decoder (opts: Tracker.RenderOptions + DecodeOptions) function Far.open(r: Bytes.Reader, opts: any?): (Types.Decoder?, Err.Err?) local m, err = Far.decode(r, opts) if not m then diff --git a/src/Rosetta/music/hmp/init.luau b/src/Rosetta/music/hmp/init.luau index f6a7e65..e2ea95f 100644 --- a/src/Rosetta/music/hmp/init.luau +++ b/src/Rosetta/music/hmp/init.luau @@ -1,14 +1,7 @@ --!strict --- music/hmp: Human Machine Interfaces SOS music: HMP ("HMIMIDIP", and the newer "HMIMIDIP013195" with the bigger header) --- and HMI ("HMI-MIDISONG061595"), as used by Descent, Duke Nukem 3D's predecessors and other DOS games. Written from the --- HMP / HMI layout notes (header fields, chunk tables, the reversed delta encoding of HMP, HMI's note durations and FE --- events); wildmidi was used only as a reference converter in tests. Decodes to a Types.Midi (format 1, one track per --- chunk): HMP deltas (7-bit groups least significant first, the last byte flagged) and running status; loop marker --- controllers 110 / 111 with a value above 127 are skipped (meta.source.loops counts them); HMI note-ons carry a --- duration that becomes a note-off (velocity 64), HMI-only FE events are skipped. Time: the header's tick rate (HMP --- at 0x38, HMI byte 212) in ticks per second, as division 60 at 60000000 / rate us per quarter; tempo events in the --- tracks apply on top. Renders through codecs/audio/MidiRender. --- Not supported: writing; HMP branch tables (skipped). +-- music/hmp: HMI SOS music: HMP ("HMIMIDIP", "HMIMIDIP013195") and HMI ("HMI-MIDISONG061595"), from the layout +-- notes (wildmidi only as a test reference). Decodes to a Types.Midi (format 1, a track per chunk; the tick rate at +-- HMP 0x38 / HMI byte 212, as division 60). Not supported: writing, HMP branch tables. -- ------------------------------------------------------------------------------------------------ requires local Err = require("@rosetta/core/Err") @@ -43,8 +36,7 @@ local readu8, readu32 = buffer.readu8, buffer.readu32 local DATA = { [8] = 2, [9] = 2, [10] = 2, [11] = 2, [12] = 1, [13] = 1, [14] = 2 } local TYPES = { [8] = "noteOff", [9] = "noteOn", [10] = "aftertouch", [11] = "controller", [12] = "program", [13] = "channelPressure", [14] = "pitchBend" } --- a delta at p -> value, next p (nil past e). hmp: least significant group first, the last byte has bit 7 set; --- otherwise the MIDI encoding +-- HMP deltas: 7-bit groups, least significant first, the last byte has bit 7 set; HMI: the MIDI encoding local function delta(b: buffer, p: number, e: number, hmp: boolean): (number?, number) local v, shift = 0, 1 for _ = 1, 5 do @@ -79,14 +71,13 @@ end type Ctx = { loops: number, budget: number } --- one track [p, e) -> events (note-offs merged in) | nil, message local function track(b: buffer, p: number, e: number, hmp: boolean, ctx: Ctx): ({ Types.MidiEvent }?, string?) local list: { Types.MidiEvent }, offs: { Render.PendingOff } = {}, {} local tick, running = 0, 0 while p < e do local d, q = delta(b, p, e, hmp) if not d then - break -- (a track cut inside its last delta: keep what was read) + break end tick += d p = q @@ -170,7 +161,6 @@ local function track(b: buffer, p: number, e: number, hmp: boolean, ctx: Ctx): ( return out, nil end --- the chunk table -> { { start, stop } } track ranges | nil, message, kind local function hmpTracks(b: buffer, base: number, limit: number): ({ { number } }?, string?, string?) local new = buffer.readstring(b, base + 8, 6) == "013195" local n = readu32(b, base + 0x30) @@ -261,7 +251,6 @@ function Hmp.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Midi?, Err.Er end -- ------------------------------------------------------------------------------------------------ open --- open(r, opts?) -> the rendered audio Decoder (opts: DecodeOptions + MidiRender.RenderOptions) function Hmp.open(r: Bytes.Reader, opts: any?): (Types.Decoder?, Err.Err?) local midi, err = Hmp.decode(r, opts) if not midi then diff --git a/src/Rosetta/music/hvl/init.luau b/src/Rosetta/music/hvl/init.luau index ea0f81a..92cb27e 100644 --- a/src/Rosetta/music/hvl/init.luau +++ b/src/Rosetta/music/hvl/init.luau @@ -1,10 +1,7 @@ --!strict --- music/hvl: HivelyTracker modules, "HVL\0" / "HVL\1": AHX's synth extended to 4..16 channels, two effect columns, --- ring modulation, per-channel panning, mix gain and stereo separation stored in the file. Loads into a Types.Module- --- shaped value (kind "music", format "hvl": tracks as patterns, positions with per-channel transposes, instruments with --- play lists, subsongs) and renders through codecs/audio/Hively, a port of HivelyTracker's hvl2wav replayer --- (BSD-3-Clause): at 44.1 kHz the samples equal hvl2wav's. --- Not supported: writing. +-- music/hvl: HivelyTracker modules, "HVL\0" / "HVL\1" (AHX extended: 4..16 channels, two effect columns, ring +-- modulation, panning, stereo separation), rendered through codecs/audio/Hively (a port of hvl2wav, BSD-3-Clause; at +-- 44.1 kHz equal to hvl2wav). Not supported: writing. -- ------------------------------------------------------------------------------------------------ requires local Err = require("@rosetta/core/Err") @@ -23,7 +20,7 @@ local Hvl = { } -- ------------------------------------------------------------------------------------------------ types -export type RenderOptions = Hively.RenderOptions -- sampleRate, subsong, loop, maxDuration (stereo: the file's) +export type RenderOptions = Hively.RenderOptions -- stereo comes from the file -- ------------------------------------------------------------------------------------------------ sniff function Hvl.sniff(r: Bytes.Reader): number @@ -41,7 +38,6 @@ function Hvl.decode(r: Bytes.Reader, _opts: any?): (Types.Module?, Err.Err?) end -- ------------------------------------------------------------------------------------------------ open --- open(r, opts?) -> the rendered audio Decoder (opts: RenderOptions) function Hvl.open(r: Bytes.Reader, opts: RenderOptions?): (Types.Decoder?, Err.Err?) local song, err = Hvl.decode(r) if not song then diff --git a/src/Rosetta/music/it/Itsex.luau b/src/Rosetta/music/it/Itsex.luau index 3a7daca..7176086 100644 --- a/src/Rosetta/music/it/Itsex.luau +++ b/src/Rosetta/music/it/Itsex.luau @@ -1,15 +1,11 @@ --!strict --!native --- music/it/Itsex: Impulse Tracker sample decompression (IT 2.14 and the IT 2.15 double-delta variant, 8 and 16-bit). --- Written from the algorithm description in ITTECH.TXT / the public notes on the format: blocks of 0x8000 bytes of --- output, each a u16 length then an LSB-first bit stream of deltas with three width-change methods. --- --- Never throws: every read is bounds-checked; corrupt streams return nil, message. +-- music/it/Itsex: IT 2.14 / 2.15 (double-delta) sample decompression, from ITTECH.TXT: 0x8000-byte output blocks, each +-- a u16 length then an LSB-first bit stream of deltas with three width-change methods. local readu8, readu16, writef32 = buffer.readu8, buffer.readu16, buffer.writef32 local Itsex = {} --- decompress(buf, off, limit, frames, bits, it215) -> f32 buffer (frames), bytes consumed | nil, message function Itsex.decompress(buf: buffer, off: number, limit: number, frames: number, bits: number, it215: boolean): (buffer?, number | string) local out = buffer.create(frames * 4) local blockLen = if bits == 16 then 0x4000 else 0x8000 @@ -34,7 +30,6 @@ function Itsex.decompress(buf: buffer, off: number, limit: number, frames: numbe return nil, "compressed block runs past the end" end p = bend - -- bit reader over [bstart, bend) local bytePos = bstart local bitBuf = 0 local bitCount = 0 @@ -90,7 +85,6 @@ function Itsex.decompress(buf: buffer, off: number, limit: number, frames: numbe continue end end - -- a delta, sign-extended from its width local x = v if width < topWidth then local shift = 2 ^ width diff --git a/src/Rosetta/music/it/init.luau b/src/Rosetta/music/it/init.luau index d271f18..bc58101 100644 --- a/src/Rosetta/music/it/init.luau +++ b/src/Rosetta/music/it/init.luau @@ -1,12 +1,7 @@ --!strict --- music/it: Impulse Tracker modules (IMPM, ITTECH.TXT; also files from OpenMPT / Schism Tracker). Reads into the --- codecs/audio/Tracker Module and plays through its engine (Module:render() / open() -> an audio Decoder). Supports: up to --- 64 channels, instrument and sample mode, new and old (pre-2.0) instrument headers, volume / panning / pitch (or --- filter) envelopes with loops and sustain loops, new note actions and duplicate checks, pitch-pan separation, --- resonant filters (instrument cutoff / resonance, default Zxx macros), 8 / 16-bit signed or unsigned mono / stereo --- samples, IT 2.14 / 2.15 compressed samples, sustain loops, auto-vibrato, the song message. --- Not supported: embedded MIDI macro configurations (the default filter macros are used), MIDI output, OpenMPT's --- extension chunks (plugins, extended instrument properties), writing. +-- music/it: Impulse Tracker modules (IMPM, ITTECH.TXT), played through codecs/audio/Tracker. Supports: 64 channels, +-- instrument / sample mode, old and new instrument headers, envelopes, NNAs, resonant filters (default Zxx macros), +-- IT 2.14 / 2.15 compressed samples, the message. Not supported: embedded MIDI macros, OpenMPT extensions, writing. -- ------------------------------------------------------------------------------------------------ requires local Err = require("@rosetta/core/Err") @@ -26,7 +21,7 @@ local It = { } export type DecodeOptions = { - maxBytes: number?, -- refuse more sample data in total (f32 bytes, default 2^28) + maxBytes: number?, -- f32 bytes of sample data in total, default 2^28 } -- ------------------------------------------------------------------------------------------------ sniff @@ -173,7 +168,6 @@ function It.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) if r.err then return nil, r.err end - -- channels: the highest one any pattern uses local nch = 1 local packed: { Bytes.Reader? } = {} local rowsOf: { number } = {} @@ -187,7 +181,6 @@ function It.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) end local data = pr:slice(len) packed[p], rowsOf[p] = data, rows - -- scan for the channel count local scan = data:sub(0) local seen: { [number]: number } = {} while not scan:eof() do @@ -258,7 +251,6 @@ function It.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) local mr = r:sub(msgOff, msgLen) m.meta.message = string.gsub(mr:fixed(msgLen), "\r", "\n") end - -- instruments for i = 1, insnum do local ins, ierr = readInstrument(r:sub(insOff[i]), cmwt < 0x200) if not ins then @@ -266,7 +258,6 @@ function It.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) end m.instruments[i] = ins end - -- samples local total = 0 for i = 1, smpnum do local h = r:sub(smpOff[i], 80) @@ -348,7 +339,6 @@ function It.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) end end end - -- patterns for p = 1, patnum do local pat = Tracker.newPattern(rowsOf[p], nch) m.patterns[p] = pat @@ -415,7 +405,6 @@ function It.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) end -- ------------------------------------------------------------------------------------------------ open --- open(r, opts) -> the module rendered as an audio Decoder (opts: Tracker.RenderOptions + DecodeOptions) function It.open(r: Bytes.Reader, opts: any?): (Types.Decoder?, Err.Err?) local m, err = It.decode(r, opts) if not m then diff --git a/src/Rosetta/music/med/init.luau b/src/Rosetta/music/med/init.luau index 0956498..fb4154a 100644 --- a/src/Rosetta/music/med/init.luau +++ b/src/Rosetta/music/med/init.luau @@ -1,14 +1,7 @@ --!strict --- music/med: MED / OctaMED modules (MMD0, MMD1, MMD2, MMD3; Amiga MED 2+, OctaMED 4 .. Soundstudio; 1..64 tracks, --- blocks of any length). Ported from OpenMPT's Load_med.cpp (BSD, licenses/openmpt-LICENSE.txt). Reads the first song --- into the codecs/audio/Tracker Module and plays it as the "xm" effect family with ProTracker periods and the PAL --- clock (flags.periods = "amiga"): MED's effects mapped as OpenMPT maps them, slides on every tick unless the song asks --- for ProTracker-style slides, the SPD / 8-channel / BPM tempo modes, MMD2 / MMD3 play sequences and sections (stop --- and jump commands), track volumes and pans, hold / decay (as a volume envelope and fadeout), IFF multi-octave --- samples (instruments with keymaps), 8 / 16-bit, stereo and delta samples, instrument extras (finetune, loops, --- default pitch, volume). --- Not supported: synthetic and hybrid instruments (silent), MIDI instruments and commands, extra command pages and --- the second command parameter, songs past the first, echo / stereo separation, packed (ADPCM) samples, writing. +-- music/med: MED / OctaMED modules (MMD0..MMD3), ported from OpenMPT's Load_med.cpp (BSD, +-- licenses/openmpt-LICENSE.txt); the first song plays as the "xm" family with Amiga periods. Supports: 1..64 tracks, +-- play sequences, hold / decay, IFF multi-octave samples. Not supported: synth / MIDI instruments, echo, writing. -- ------------------------------------------------------------------------------------------------ requires local Err = require("@rosetta/core/Err") @@ -28,7 +21,7 @@ local Med = { } export type DecodeOptions = { - maxBytes: number?, -- refuse more sample data in total (f32 bytes, default 2^28) + maxBytes: number?, -- f32 bytes of sample data in total, default 2^28 } -- ------------------------------------------------------------------------------------------------ constants @@ -78,7 +71,7 @@ end -- ------------------------------------------------------------------------------------------------ decode type Ctx = { transpose: number, is8Ch: boolean, softMix: boolean, bpm: boolean, rowsPerBeat: number, volHex: boolean, vol7bit: boolean } --- a MED tempo -> BPM (OpenMPT's MMDTempoToBPM: the SPD / 8-channel / BPM modes) +-- OpenMPT's MMDTempoToBPM (SPD / 8-channel / BPM modes) local function tempoToBpm(tempo: number, ctx: Ctx): number if ctx.bpm and not ctx.is8Ch then return if tempo < 7 then 111.5 else tempo * ctx.rowsPerBeat / 4 @@ -93,7 +86,7 @@ local function tempoToBpm(tempo: number, ctx: Ctx): number return tempo / 0.264 end --- a MED command -> MOD / XM effect, param, and a note-cut flag (OpenMPT's ConvertMEDEffect) +-- MED command -> MOD / XM effect, param, note-cut flag: OpenMPT's ConvertMEDEffect local function effect(cmd: number, p: number, ctx: Ctx): (number, number, boolean) local lo = math.min(p, 15) if cmd == 1 or cmd == 2 then @@ -179,7 +172,7 @@ local function effect(cmd: number, p: number, ctx: Ctx): (number, number, boolea return 0, 0, false end --- a MED note (with the play transpose) -> our note, or 0 (OpenMPT's octave wrapping) +-- OpenMPT's octave wrapping local function wrapNote(note: number, vol7bit: boolean): number local n = note + 12 -- OpenMPT's numbering (ProTracker notes an octave up) if n > 132 and not vol7bit then @@ -190,7 +183,6 @@ local function wrapNote(note: number, vol7bit: boolean): number return if n >= 13 then n - 12 else 0 end --- one block -> a Pattern (the main command page); returns whether a note needs the instruments' octave folding local function readBlock(r: Bytes.Reader, off: number, version: number, ctx: Ctx, nch: number): (any?, boolean) local br = r:sub(off) local ntracks, nrows, info @@ -300,7 +292,6 @@ function Med.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) if numSamples > 0 and smpOff == 0 then return nil, Err.new(Err.CORRUPT, "no sample table") end - -- channels: the widest block (at least 4) local nch = 4 local blockPtr: { number } = {} for b = 0, numBlocks - 1 do @@ -339,7 +330,6 @@ function Med.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) if ext.nameOff > 0 and ext.nameLen > 0 then m.title = r:sub(ext.nameOff, math.min(ext.nameLen, 256)):fixed(math.min(ext.nameLen, 256)) end - -- instruments and samples local needInstruments = false local instruments, samples = {}, {} local unsupported = {} @@ -419,7 +409,6 @@ function Med.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) end end end - -- sample data local list = {} for i = 0, count - 1 do local s = Tracker.newSample(name) @@ -454,7 +443,6 @@ function Med.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) frames, ls, le = frames * 2, ls * 2, le * 2 end end - -- the instrument extras if xsize > 0 then if x.hold > 0 and not isSynth then local env = Tracker.newEnvelope() @@ -591,7 +579,6 @@ function Med.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) end end m.preamp = preamp - -- tempo, speed, volume, the pattern context local ctx: Ctx = { transpose = 36 + playTranspose - (if version > 2 then 24 else 0), is8Ch = bit32.band(flags, 0x40) ~= 0, @@ -606,7 +593,6 @@ function Med.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) if masterVol > 0 then m.globalVolume = math.min(masterVol, 64) * 2 end - -- blocks for b = 0, numBlocks - 1 do local p = blockPtr[b + 1] local pat, high = nil, false @@ -620,7 +606,6 @@ function Med.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) for at, to in jumps do local prev = m.order[at - 1] if prev and prev < 254 and m.patterns[prev + 1] then - -- the block may be played elsewhere: give this order entry its own copy local src = m.patterns[prev + 1] local cp = Tracker.newPattern(src.rows, nch) buffer.copy(cp.data, 0, src.data) @@ -649,7 +634,6 @@ function Med.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) end -- ------------------------------------------------------------------------------------------------ open --- open(r, opts) -> the module rendered as an audio Decoder (opts: Tracker.RenderOptions + DecodeOptions) function Med.open(r: Bytes.Reader, opts: any?): (Types.Decoder?, Err.Err?) local m, err = Med.decode(r, opts) if not m then diff --git a/src/Rosetta/music/midi/Smf.luau b/src/Rosetta/music/midi/Smf.luau index fc7dfac..85d99c1 100644 --- a/src/Rosetta/music/midi/Smf.luau +++ b/src/Rosetta/music/midi/Smf.luau @@ -1,10 +1,6 @@ --!strict --- music/midi/Smf: Standard MIDI File chunks <-> Types.Midi. Reads MThd / MTrk (formats 0, 1, 2; PPQ and SMPTE --- divisions; running status, also across meta / sysex events as most players accept), skips unknown chunks, unwraps --- RIFF RMID. Writes MThd + MTrk with optional running status; with running status on (the default) the bytes are --- those python mido writes for the same events (running status reset after meta / sysex, one end-of-track at the --- end, mid-track end-of-track events dropped); a track's name is written as a 0x03 event at tick 0 when the track --- has none. Written from the SMF 1.0 specification (no third-party code). +-- music/midi/Smf: SMF 1.0 MThd / MTrk <-> Types.Midi (running status also across meta / sysex, RIFF RMID unwrapped). +-- Writes what python mido writes: running status reset after meta / sysex, one end-of-track, track names at tick 0. local Err = require("@rosetta/core/Err") local Bytes = require("@rosetta/core/Bytes") local Types = require("@rosetta/Types") @@ -43,13 +39,11 @@ end Smf.text = text -- ------------------------------------------------------------------------------------------------ read --- one MTrk body [p, e): events | nil, message, truncated local function readTrack(b: buffer, p: number, e: number, budget: { number }): ({ Types.MidiEvent }?, string?, boolean) local events: { Types.MidiEvent } = {} local tick = 0 local running = 0 while p < e do - -- delta time local delta, n = 0, 0 repeat if p >= e then @@ -140,7 +134,6 @@ local function readTrack(b: buffer, p: number, e: number, budget: { number }): ( return events, nil, false end --- read(r, opts?) -> Midi | nil, Err function Smf.read(r: Bytes.Reader, opts: ReadOptions?): (Types.Midi?, Err.Err?) local strict = opts and opts.strict or false local budget = { opts and opts.maxEvents or 2 ^ 24 } @@ -267,7 +260,6 @@ local function byteList(d: any, want: number?): { number }? return d end --- write(midi, opts?) -> buffer | nil, Err function Smf.write(midi: Types.Midi, opts: WriteOptions?): (buffer?, Err.Err?) if type(midi) ~= "table" or type(midi.tracks) ~= "table" then return nil, Err.new(Err.ARG, "needs a Midi value with tracks") @@ -298,7 +290,6 @@ function Smf.write(midi: Types.Midi, opts: WriteOptions?): (buffer?, Err.Err?) if type(events) ~= "table" then return nil, Err.new(Err.ARG, "track " .. ti .. " has no events list") end - -- stable order by tick local sorted = true local last = 0 for i, ev in events do @@ -324,7 +315,7 @@ function Smf.write(midi: Types.Midi, opts: WriteOptions?): (buffer?, Err.Err?) return order[a] < order[c] end) end - -- track.name: written as a track-name meta event (0x03) at tick 0 when the track has none of its own +-- a track-name meta event (0x03) at tick 0 when the track has none (as mido) if type(track.name) == "string" and track.name ~= "" then local named = false for _, ev in list do diff --git a/src/Rosetta/music/midi/init.luau b/src/Rosetta/music/midi/init.luau index 1611da1..0d6c0c0 100644 --- a/src/Rosetta/music/midi/init.luau +++ b/src/Rosetta/music/midi/init.luau @@ -1,14 +1,7 @@ --!strict --- music/midi: Standard MIDI Files (SMF 1.0: formats 0, 1 and 2; PPQ and SMPTE time; RIFF RMID read). Written from the --- specification (no third-party code); rendering goes through codecs/audio/SoundFont (a TinySoundFont port). --- Supports: decode to a Types.Midi (absolute ticks; channel events noteOff / noteOn / aftertouch / controller / --- program / channelPressure / pitchBend with their raw data bytes, sysex / escape with the bytes after the length, --- meta events with meta = the meta type; meta.tempos / timeSignatures / keySignatures, track names; .kar karaoke: --- meta.lyrics = { { time, tick, text } } from the "Words" track's text events (FF 01; the @ headers go to --- meta.karaoke and meta.tags) and from lyric events (FF 05), in time order), encode (running --- status optional, byte-identical to python mido's writer by default), the tempo map (tickToSeconds, length), and --- render / open: an audio Decoder (stereo f32) through an SF2 SoundFont (opts.soundfont) or the built-in waveform set. --- Not supported: RMID write, XMF / RMI DLS banks, system common / realtime bytes inside tracks (CORRUPT). +-- music/midi: Standard MIDI Files (SMF 1.0 formats 0 / 1 / 2, PPQ and SMPTE; RIFF RMID read), from the spec. Supports: +-- decode to a Types.Midi, .kar lyrics, encode (byte-identical to python mido by default), the tempo map, rendering +-- through codecs/audio/SoundFont. Not supported: RMID write, XMF / DLS banks, system common bytes in tracks. -- ------------------------------------------------------------------------------------------------ requires local Err = require("@rosetta/core/Err") @@ -30,7 +23,7 @@ local Midi = { -- ------------------------------------------------------------------------------------------------ types export type DecodeOptions = Smf.ReadOptions -- strict (default false), maxEvents (default 2^24) export type EncodeOptions = Smf.WriteOptions -- runningStatus (default true) -export type RenderOptions = Render.RenderOptions -- sampleRate, soundfont, gain, tail, maxVoices +export type RenderOptions = Render.RenderOptions -- ------------------------------------------------------------------------------------------------ sniff function Midi.sniff(r: Bytes.Reader): number @@ -44,8 +37,7 @@ function Midi.sniff(r: Bytes.Reader): number end -- ------------------------------------------------------------------------------------------------ decode --- karaoke(midi): .kar text (FF 01 in a track named "Words", or in any track once an "@K" / "@T" header shows up) and --- FF 05 lyric events -> meta.lyrics; "@X" headers -> meta.karaoke[X] (lists of lines) and meta.tags +-- .kar: FF 01 text in a "Words" track (or after an "@K" / "@T" header) and FF 05 lyrics; "@X" headers -> meta.karaoke[X] local function karaoke(midi: Types.Midi) local lyrics: { { time: number, tick: number, text: string } } = {} local headers: { [string]: { string } } = {} @@ -119,7 +111,6 @@ function Midi.encode(midi: Types.Midi, opts: EncodeOptions?): (buffer?, Err.Err? end -- ------------------------------------------------------------------------------------------------ open --- open(r, opts?) -> the rendered audio Decoder (opts: DecodeOptions + RenderOptions) function Midi.open(r: Bytes.Reader, opts: any?): (Types.Decoder?, Err.Err?) local midi, err = Midi.decode(r, opts) if not midi then @@ -129,26 +120,22 @@ function Midi.open(r: Bytes.Reader, opts: any?): (Types.Decoder?, Err.Err?) end -- ------------------------------------------------------------------------------------------------ extras --- render(midi, opts?) -> Decoder | nil, Err (also works on a Midi built by hand with Types.Midi.new) function Midi.render(midi: Types.Midi, opts: RenderOptions?): (Types.Decoder?, Err.Err?) return Render.decoder(midi, opts) end --- tickToSeconds(midi, tick, track?) -> seconds (track: format 2's per-track tempo map) function Midi.tickToSeconds(midi: Types.Midi, tick: number, track: number?): number return Render.seconds(Render.tempoMap(midi, track), tick) end --- tempoMap(midi, track?) -> { ticks, secs, us, division } (change points) Midi.tempoMap = Render.tempoMap Midi.seconds = Render.seconds --- length(midi) -> seconds to the last event (what python mido's MidiFile.length reports for formats 0 / 1) +-- as python mido's MidiFile.length (formats 0 / 1) function Midi.length(midi: Types.Midi): number return Render.length(midi) end --- text(data) -> the bytes of a text meta event as a string Midi.text = Smf.text return Midi diff --git a/src/Rosetta/music/mod/init.luau b/src/Rosetta/music/mod/init.luau index 1309897..e2fe34e 100644 --- a/src/Rosetta/music/mod/init.luau +++ b/src/Rosetta/music/mod/init.luau @@ -1,11 +1,7 @@ --!strict --- music/mod: ProTracker / NoiseTracker / StarTrekker MOD modules (the 31-sample "M.K." family: M.K., M!K!, FLT4, --- 4CHN .. 9CHN, 10CH .. 32CH, xxCN, CD81, OKTA / OCTA, TDZx; 15-sample Soundtracker files when asked for by name or --- extension). Written from the ProTracker 2.3 documentation. Reads into the codecs/audio/Tracker Module and plays through --- its engine (Module:render() / open() -> an audio Decoder). Writes 31-sample MODs (M.K. / xCHN / xxCH) from "mod" --- modules, and from XM modules that fit (one sample per instrument, effects 0..F, 64-row patterns). --- Not supported: FLT8's split 4 + 4 channel patterns (read as 8 plain channels), the Amiga hardware low-pass filter --- (E0x), PowerPacker-packed files. +-- music/mod: ProTracker / NoiseTracker / StarTrekker MODs (M.K., M!K!, FLT4, xCHN, xxCH, xxCN, CD81, OKTA, TDZx; +-- 15-sample Soundtracker by name or extension), from the ProTracker 2.3 docs. Writes 31-sample MODs from "mod" modules +-- and XM ones that fit. Not supported: FLT8's split patterns (read as 8 channels), the E0x filter, PowerPacker files. -- ------------------------------------------------------------------------------------------------ requires local Err = require("@rosetta/core/Err") @@ -24,7 +20,7 @@ local Mod = { } export type DecodeOptions = { - maxBytes: number?, -- refuse bigger sample data in total (default 64 MB of f32 samples) + maxBytes: number?, -- f32 bytes of sample data in total, default 64 MB } export type EncodeOptions = {} @@ -46,7 +42,7 @@ local FIXED: { [string]: number } = { ["EXO8"] = 8, } --- channels from the 4-byte signature at 1080, or nil +-- the 4-byte signature at offset 1080 local function signatureChannels(sig: string): number? local fixed = FIXED[sig] if fixed then @@ -143,7 +139,6 @@ function Mod.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) m.restart = if restart < songLength then restart else 0 m.meta.signature = if nsamples == 31 then sig else nil m.flags.amigaLimits = nch == 4 - -- patterns local npat = maxPat + 1 local patBytes = 64 * nch * 4 if not r:need(npat * patBytes) then @@ -168,7 +163,7 @@ function Mod.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) m.patterns[p + 1] = pat end r:skip(npat * patBytes) - -- sample data (8-bit signed; the last samples of a truncated file are cut short) +-- sample data: 8-bit signed local total = 0 for i = 1, nsamples do local s = m.samples[i] @@ -206,8 +201,6 @@ local function writeName(w: Bytes.Writer, s: string, n: number) w:fill(0, n - #t) end --- encode(module) -> MOD bytes. The module must be "mod", or an "xm" module whose instruments each map every note to --- one sample; patterns must have 64 rows, at most 31 samples, effects 0..F. function Mod.encode(m: any, _opts: EncodeOptions?): (buffer?, Err.Err?) local ok, verr = Tracker.validate(m) if not ok then @@ -220,7 +213,6 @@ function Mod.encode(m: any, _opts: EncodeOptions?): (buffer?, Err.Err?) if nch > 32 then return nil, Err.new(Err.ARG, "MOD holds at most 32 channels") end - -- the sample for each instrument number local smpOf: { any } = {} if m.format == "xm" then for i, ins in m.instruments do @@ -273,7 +265,6 @@ function Mod.encode(m: any, _opts: EncodeOptions?): (buffer?, Err.Err?) local len = math.min(s.length, 131070) local pcm = Pcm.encode(s.data, len, { bits = 8, signed = true, channels = 1 }) if s.channels == 2 then - -- mix stereo samples down local mono = buffer.create(len * 4) for k = 0, len - 1 do buffer.writef32(mono, k * 4, (buffer.readf32(s.data, k * 8) + buffer.readf32(s.data, k * 8 + 4)) / 2) @@ -349,7 +340,6 @@ function Mod.encode(m: any, _opts: EncodeOptions?): (buffer?, Err.Err?) end -- ------------------------------------------------------------------------------------------------ open --- open(r, opts) -> the module rendered as an audio Decoder (opts: Tracker.RenderOptions + DecodeOptions) function Mod.open(r: Bytes.Reader, opts: any?): (Types.Decoder?, Err.Err?) local m, err = Mod.decode(r, opts) if not m then diff --git a/src/Rosetta/music/mtm/init.luau b/src/Rosetta/music/mtm/init.luau index 622dea1..e8b4d8d 100644 --- a/src/Rosetta/music/mtm/init.luau +++ b/src/Rosetta/music/mtm/init.luau @@ -1,10 +1,7 @@ --!strict --- music/mtm: MultiTracker modules (MTM, Renaissance's DOS tracker, 1..32 channels; patterns built from shared --- tracks). Ported from OpenMPT's Load_mtm.cpp (BSD, licenses/openmpt-LICENSE.txt). Reads into the --- codecs/audio/Tracker Module and plays as the "xm" effect family with Amiga periods (OpenMPT plays MTM like XM): --- MOD effects (no 8xx panning, E8x pans), 8 / 16-bit unsigned samples, finetune, the song speed / tempo quirk --- (MultiTracker resets the tempo on a speed command and the speed on a tempo command when they never share a row). --- Not supported: MultiTracker's E9x / EDx retrigger timing and its vibrato start phase (played as in XM), writing. +-- music/mtm: MultiTracker modules (MTM, 1..32 channels, patterns of shared tracks), ported from OpenMPT's Load_mtm.cpp +-- (BSD, licenses/openmpt-LICENSE.txt); played as the "xm" family with Amiga periods, as OpenMPT does. Not supported: +-- MultiTracker's E9x / EDx retrigger timing and vibrato start phase (played as in XM), writing. -- ------------------------------------------------------------------------------------------------ requires local Err = require("@rosetta/core/Err") @@ -24,7 +21,7 @@ local Mtm = { } export type DecodeOptions = { - maxBytes: number?, -- refuse more sample data in total (f32 bytes, default 2^28) + maxBytes: number?, -- f32 bytes of sample data in total, default 2^28 } -- ------------------------------------------------------------------------------------------------ sniff @@ -104,7 +101,6 @@ function Mtm.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) for i = 1, nch do m.channelPan[i] = (pans[i] % 16) * 16 + 8 end - -- samples local sizes: { number } = {} for i = 1, numSamples do local s = Tracker.newSample(r:fixed(22)) @@ -135,7 +131,6 @@ function Mtm.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) s.length = frames m.samples[i] = s end - -- the order list for i = 1, 128 do local o = r:u8() if i <= lastOrder + 1 then @@ -214,7 +209,6 @@ function Mtm.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) end -- ------------------------------------------------------------------------------------------------ open --- open(r, opts) -> the module rendered as an audio Decoder (opts: Tracker.RenderOptions + DecodeOptions) function Mtm.open(r: Bytes.Reader, opts: any?): (Types.Decoder?, Err.Err?) local m, err = Mtm.decode(r, opts) if not m then diff --git a/src/Rosetta/music/mus/init.luau b/src/Rosetta/music/mus/init.luau index c4c1ee3..5ee9290 100644 --- a/src/Rosetta/music/mus/init.luau +++ b/src/Rosetta/music/mus/init.luau @@ -1,13 +1,7 @@ --!strict --- music/mus: DMX MUS, the music format of Doom, Heretic, Hexen and Strife ("MUS\x1a"). Written from the MUS format --- description (Vladimir Arnost's "MUS File Format", the DMX event set); wildmidi was used only as a reference converter --- in tests. Decodes to a Types.Midi (format 0, one track) the way the usual MUS-to-MIDI converters map it: MUS channel --- 15 is the percussion channel 9, the others get MIDI channels 0..8, 10..15 in order of first use (each starting at --- volume 127), MUS controllers / system events become MIDI controllers (controller 0 = program change), notes without --- a volume reuse the channel's last one (127 at first), pitch wheel 0..255 becomes a 14-bit bend. Time: 140 ticks per --- second (opts.rate), as division 70 at 500000 us per quarter. Renders through codecs/audio/MidiRender (SoundFont / --- built-in waveforms). meta.source: primaryChannels, secondaryChannels, instruments (the patch list), rate. --- Not supported: writing (save as .mid through the midi format's encoder). +-- music/mus: DMX MUS ("MUS\x1a"; Doom, Heretic, Hexen, Strife), from Vladimir Arnost's "MUS File Format" (wildmidi +-- only as a test reference). Decodes to a Types.Midi as the usual converters map it (MUS channel 15 -> 9; 140 ticks/s +-- as division 70 at 500000 us per quarter). Not supported: writing (encode as .mid with the midi format). -- ------------------------------------------------------------------------------------------------ requires local Err = require("@rosetta/core/Err") @@ -43,7 +37,6 @@ end -- ------------------------------------------------------------------------------------------------ decode local readu8 = buffer.readu8 --- the score [p, e) -> events | nil, message local function score(b: buffer, p: number, e: number, primary: number, maxEvents: number): ({ Types.MidiEvent }?, string?, boolean) local events: { Types.MidiEvent } = { { tick = 0, type = "controller", channel = 9, data = { 0x07, 127 } } } local map: { [number]: number } = { [15] = 9 } @@ -151,7 +144,6 @@ function Mus.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Midi?, Err.Er end -- ------------------------------------------------------------------------------------------------ open --- open(r, opts?) -> the rendered audio Decoder (opts: DecodeOptions + MidiRender.RenderOptions) function Mus.open(r: Bytes.Reader, opts: any?): (Types.Decoder?, Err.Err?) local midi, err = Mus.decode(r, opts) if not midi then diff --git a/src/Rosetta/music/okt/init.luau b/src/Rosetta/music/okt/init.luau index 58d9d83..2cbadfd 100644 --- a/src/Rosetta/music/okt/init.luau +++ b/src/Rosetta/music/okt/init.luau @@ -1,11 +1,7 @@ --!strict --- music/okt: Oktalyzer modules (OKTASONG, Armin Sander's Amiga tracker; 4 to 8 channels: each of the Amiga's four can --- be split into a mixed pair). Ported from OpenMPT's Load_okt.cpp (BSD, licenses/openmpt-LICENSE.txt). An IFF-style --- chunk list (containers/Chunks) read into the codecs/audio/Tracker Module, played as the "it" effect family with --- ProTracker periods and the PAL clock (flags.periods = "amiga"), Amiga period limits, slides on every tick, sample --- loops as sustain loops (released by R), Oktalyzer's three arpeggios, note slides (D / U every tick, L / H once: --- flags.oktSlides), and its volume command: on a mixed pair the volume is the pair's channel volume. --- Not supported: the Amiga LED filter (F), writing. +-- music/okt: Oktalyzer modules (OKTASONG, 4..8 channels: each Amiga channel may be a mixed pair), ported from OpenMPT's +-- Load_okt.cpp (BSD, licenses/openmpt-LICENSE.txt); played as the "it" family with Amiga periods, loops as sustain +-- loops (released by R), the three arpeggios and note slides. Not supported: the LED filter (F), writing. -- ------------------------------------------------------------------------------------------------ requires local Err = require("@rosetta/core/Err") @@ -26,7 +22,7 @@ local Okt = { } export type DecodeOptions = { - maxBytes: number?, -- refuse more sample data in total (f32 bytes, default 2^28) + maxBytes: number?, -- f32 bytes of sample data in total, default 2^28 } -- ------------------------------------------------------------------------------------------------ constants @@ -39,7 +35,6 @@ function Okt.sniff(r: Bytes.Reader): number end -- ------------------------------------------------------------------------------------------------ decode --- a negative arpeggio offset as the equivalent positive one local function invert(p: number): number p %= 16 if p == 0 then @@ -48,7 +43,6 @@ local function invert(p: number): number return if p <= 12 then 12 - p else 24 - p end --- the Oktalyzer effect of a cell -> effect name?, param, volume (0..64, the volume column) or -1, a key off local function effect(e: number, p: number, paired: boolean): (string?, number, number, boolean) if e == 1 and p > 0 then return "portaup", p, -1, false -- "portamento down (period)": the period goes down @@ -274,7 +268,6 @@ function Okt.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) end -- ------------------------------------------------------------------------------------------------ open --- open(r, opts) -> the module rendered as an audio Decoder (opts: Tracker.RenderOptions + DecodeOptions) function Okt.open(r: Bytes.Reader, opts: any?): (Types.Decoder?, Err.Err?) local m, err = Okt.decode(r, opts) if not m then diff --git a/src/Rosetta/music/ptm/init.luau b/src/Rosetta/music/ptm/init.luau index f24eb73..10a438b 100644 --- a/src/Rosetta/music/ptm/init.luau +++ b/src/Rosetta/music/ptm/init.luau @@ -1,11 +1,7 @@ --!strict --- music/ptm: PolyTracker modules (PTMF, Lone Ranger's DOS tracker; up to 32 channels, S3M-like packed patterns, MOD --- effect letters). Ported from OpenMPT's Load_ptm.cpp (BSD, licenses/openmpt-LICENSE.txt). Reads into the --- codecs/audio/Tracker Module and plays as the "it" effect family with Amiga periods, IT old effects and linked Gxx --- memory (as OpenMPT converts PTM): MOD effects whose slides take S3M-style fine values, global volume, retrigger, --- fine vibrato and the note slides (G..J: Tracker.EXT), delta-coded 8-bit and 16-bit samples (8-bit deltas of the --- byte stream, as PolyTracker stores them), ping-pong loops. --- Not supported: reverse sample offset (K), sample offsets scaled for 16-bit samples, writing. +-- music/ptm: PolyTracker modules (PTMF, up to 32 channels), ported from OpenMPT's Load_ptm.cpp (BSD, +-- licenses/openmpt-LICENSE.txt); played as the "it" family with Amiga periods, as OpenMPT converts PTM. Not supported: +-- reverse sample offset (K), sample offsets scaled for 16-bit samples, writing. -- ------------------------------------------------------------------------------------------------ requires local Err = require("@rosetta/core/Err") @@ -25,7 +21,7 @@ local Ptm = { } export type DecodeOptions = { - maxBytes: number?, -- refuse more sample data in total (f32 bytes, default 2^28) + maxBytes: number?, -- f32 bytes of sample data in total, default 2^28 } -- ------------------------------------------------------------------------------------------------ constants @@ -59,7 +55,6 @@ local function delta16(buf: buffer, off: number, frames: number, limit: number): return raw, n end --- a PolyTracker effect -> name?, param local function effect(cmd: number, param: number): (string?, number) if cmd == 0x10 then return "globalvol", math.min(param, 0x40) * 2 @@ -154,7 +149,6 @@ function Ptm.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) if r.err then return nil, r.err end - -- samples local buf = r.buf for i = 1, nsmp do local h = r:slice(80) @@ -215,7 +209,6 @@ function Ptm.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) end -- ------------------------------------------------------------------------------------------------ open --- open(r, opts) -> the module rendered as an audio Decoder (opts: Tracker.RenderOptions + DecodeOptions) function Ptm.open(r: Bytes.Reader, opts: any?): (Types.Decoder?, Err.Err?) local m, err = Ptm.decode(r, opts) if not m then diff --git a/src/Rosetta/music/s3m/init.luau b/src/Rosetta/music/s3m/init.luau index 0852553..6b14b5d 100644 --- a/src/Rosetta/music/s3m/init.luau +++ b/src/Rosetta/music/s3m/init.luau @@ -1,10 +1,7 @@ --!strict --- music/s3m: Scream Tracker 3 modules (SCRM, ST3 TECH.DOC; also files from Impulse Tracker / OpenMPT / Schism --- Tracker). Reads into the codecs/audio/Tracker Module and plays through its engine (Module:render() / open() -> an audio --- Decoder). Supports: up to 32 PCM channels, 8 / 16-bit signed or unsigned, mono or stereo samples, loops, the panning --- table, ST3.00 fast volume slides, every ST3 effect. Notes are stored one octave up (S3M C-4 = note 61 = the C5 --- speed reference, as IT shows S3M files). --- Not supported: AdLib (OPL) instruments and channels (read as silent), writing. +-- music/s3m: Scream Tracker 3 modules (SCRM, ST3 TECH.DOC). Supports: 32 PCM channels, 8 / 16-bit mono / stereo +-- samples, the panning table, ST3.00 fast slides, every ST3 effect; notes stored an octave up (S3M C-4 = note 61, as IT +-- shows S3M files). Not supported: AdLib (OPL) instruments (silent), writing. -- ------------------------------------------------------------------------------------------------ requires local Err = require("@rosetta/core/Err") @@ -23,7 +20,7 @@ local S3m = { } export type DecodeOptions = { - maxBytes: number?, -- refuse more sample data in total (f32 bytes, default 2^28) + maxBytes: number?, -- f32 bytes of sample data in total, default 2^28 } -- ------------------------------------------------------------------------------------------------ sniff @@ -86,7 +83,6 @@ function S3m.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) m.flags.fastSlides = cwt == 0x1300 or bit32.band(flags, 64) ~= 0 m.flags.amigaLimits = bit32.band(flags, 16) ~= 0 m.meta.source = { format = "s3m", tracker = cwt, stereo = mv >= 128 } - -- orders, parapointers, panning r:seek(96) for i = 1, ordnum do local o = r:u8() @@ -126,7 +122,6 @@ function S3m.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) m.channelPan[i] = pan m.channelMute[i] = c >= 16 end - -- samples local total = 0 local unsigned = ffi ~= 1 for i = 1, insnum do @@ -154,7 +149,6 @@ function S3m.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) local nchs = if bit32.band(sflags, 2) ~= 0 then 2 else 1 local off = (hi * 65536 + lo) * 16 len = math.min(len, 2 ^ 26) - -- a short file: keep what is there local avail = math.max(0, r:size() - off) // (nchs * bits // 8) len = math.min(len, avail) total += len * nchs * 4 @@ -170,7 +164,6 @@ function S3m.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) end end end - -- patterns for p = 1, patnum do local pat = Tracker.newPattern(64, nch) m.patterns[p] = pat @@ -230,7 +223,6 @@ function S3m.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) end -- ------------------------------------------------------------------------------------------------ open --- open(r, opts) -> the module rendered as an audio Decoder (opts: Tracker.RenderOptions + DecodeOptions) function S3m.open(r: Bytes.Reader, opts: any?): (Types.Decoder?, Err.Err?) local m, err = S3m.decode(r, opts) if not m then diff --git a/src/Rosetta/music/sf2/init.luau b/src/Rosetta/music/sf2/init.luau index f03a2a2..aac7027 100644 --- a/src/Rosetta/music/sf2/init.luau +++ b/src/Rosetta/music/sf2/init.luau @@ -1,9 +1,7 @@ --!strict --- music/sf2: SoundFont 2 banks (SoundFont 2.04 specification), read-only. A thin wrapper over codecs/audio/SoundFont (the --- parser and the TinySoundFont-port synth music/midi renders with). Supports: INFO, 16-bit samples (+ sm24 24-bit), --- presets / instruments / sample headers with global zones, generator merging into playable regions. --- Not supported: writing, SF3 (Ogg Vorbis samples), modulators (read past, not applied). --- decode returns the SoundFont value (kind "soundfont"): pass it to music/midi render as opts.soundfont. +-- music/sf2: SoundFont 2 banks (SoundFont 2.04 spec), read-only, over codecs/audio/SoundFont (a TinySoundFont port). +-- Supports: INFO, 16 / 24-bit (sm24) samples, presets / instruments with global zones, generators merged into regions. +-- Not supported: writing, SF3 (Vorbis samples), modulators (skipped). -- ------------------------------------------------------------------------------------------------ requires local Err = require("@rosetta/core/Err") @@ -37,7 +35,6 @@ function Sf2.decode(r: Bytes.Reader, opts: DecodeOptions?): (SoundFont.SoundFont end -- ------------------------------------------------------------------------------------------------ extras --- synth(sf?, sampleRate?, opts?) -> a synth State (codecs/audio/SoundFont.Synth drives it) Sf2.synth = SoundFont.synth Sf2.fallback = SoundFont.fallback diff --git a/src/Rosetta/music/stm/init.luau b/src/Rosetta/music/stm/init.luau index ec82b94..cad5581 100644 --- a/src/Rosetta/music/stm/init.luau +++ b/src/Rosetta/music/stm/init.luau @@ -1,10 +1,7 @@ --!strict --- music/stm: Scream Tracker 2 modules (STM, "!Scream!" / BMOD2STM / WUZAMOD! / SWavePro; 4 channels, 31 samples). --- Ported from OpenMPT's Load_stm.cpp (BSD, licenses/openmpt-LICENSE.txt). Reads into the codecs/audio/Tracker Module --- and plays as the "s3m" effect family with Scream Tracker 2's tempo (flags.st2Tempo: the speed byte also sets the --- tick length), no effect memory, no fine slides (the loader drops what ST2 ignores) and its deferred Bxx (the jump --- happens at the end of the pattern or at the next Cxx). --- Not supported: STX (Scream Tracker Music Interface Kit), ST2's noise for samples at volume 0 (silent here), writing. +-- music/stm: Scream Tracker 2 modules (STM, "!Scream!" / BMOD2STM / WUZAMOD! / SWavePro), ported from OpenMPT's +-- Load_stm.cpp (BSD, licenses/openmpt-LICENSE.txt); played as the "s3m" family with ST2's tempo, no effect memory and +-- its deferred Bxx. Not supported: STX, ST2's noise for samples at volume 0 (silent), writing. -- ------------------------------------------------------------------------------------------------ requires local Err = require("@rosetta/core/Err") @@ -24,7 +21,7 @@ local Stm = { } export type DecodeOptions = { - maxBytes: number?, -- refuse more sample data in total (f32 bytes, default 2^28) + maxBytes: number?, -- f32 bytes of sample data in total, default 2^28 } -- ------------------------------------------------------------------------------------------------ constants @@ -221,7 +218,6 @@ function Stm.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) end -- ------------------------------------------------------------------------------------------------ open --- open(r, opts) -> the module rendered as an audio Decoder (opts: Tracker.RenderOptions + DecodeOptions) function Stm.open(r: Bytes.Reader, opts: any?): (Types.Decoder?, Err.Err?) local m, err = Stm.decode(r, opts) if not m then diff --git a/src/Rosetta/music/ult/init.luau b/src/Rosetta/music/ult/init.luau index 7f9f004..698b075 100644 --- a/src/Rosetta/music/ult/init.luau +++ b/src/Rosetta/music/ult/init.luau @@ -1,12 +1,7 @@ --!strict --- music/ult: UltraTracker modules (MAS_UTrack_V001 .. V004; up to 32 channels, two effects per cell, patterns stored --- channel by channel with run-length repeats). Ported from OpenMPT's Load_ult.cpp (BSD, licenses/openmpt-LICENSE.txt). --- Reads into the codecs/audio/Tracker Module and plays as the "it" effect family with Amiga periods, IT old effects --- and linked Gxx memory (as OpenMPT converts ULT): the two effect columns go into the IT volume column and the effect --- column (or the more important one is kept), sample loops are sustain loops (released by a key off), the tone --- portamento keeps going on later rows. 8 / 16-bit signed samples, the v1.4+ sample speed and finetune. --- Not supported: reverse playback (5x2), "no loop" (5x1), vibrato strength (E0x), sample offsets past 64 KiB (the --- high byte is dropped), the logarithmic volumes of pre-1.4 files, writing. +-- music/ult: UltraTracker modules (MAS_UTrack_V001 .. V004, up to 32 channels), ported from OpenMPT's Load_ult.cpp +-- (BSD, licenses/openmpt-LICENSE.txt); played as the "it" family with Amiga periods, as OpenMPT converts ULT. Not +-- supported: reverse (5x2), "no loop" (5x1), E0x, offsets past 64 KiB, pre-1.4 log volumes, writing. -- ------------------------------------------------------------------------------------------------ requires local Err = require("@rosetta/core/Err") @@ -26,7 +21,7 @@ local Ult = { } export type DecodeOptions = { - maxBytes: number?, -- refuse more sample data in total (f32 bytes, default 2^28) + maxBytes: number?, -- f32 bytes of sample data in total, default 2^28 } -- ------------------------------------------------------------------------------------------------ constants @@ -45,7 +40,7 @@ function Ult.sniff(r: Bytes.Reader): number end -- ------------------------------------------------------------------------------------------------ decode --- one effect nibble + parameter -> name?, param (OpenMPT's TranslateULTCommands) +-- OpenMPT's TranslateULTCommands local function translate(e: number, param: number, version: number): (string?, number) local name = EFFECTS[e] if e == 0 then @@ -94,7 +89,7 @@ local function translate(e: number, param: number, version: number): (string?, n return name, param end --- volume slide + vibrato / tone portamento without a parameter -> one combined effect (OpenMPT's CombineEffects) +-- OpenMPT's CombineEffects (volume slide + vibrato / tone portamento without a parameter) local function combine(a: string?, pa: number, b: string?, pb: number): (string?, number, string?, number) if a == "volslide" and (b == "vibrato" or b == "toneportavol") and pb == 0 then return if b == "vibrato" then "vibratovol" else "toneportavol", pa, nil, 0 @@ -104,8 +99,7 @@ local function combine(a: string?, pa: number, b: string?, pb: number): (string? return a, pa, b, pb end --- an event: [0xFC repeat] note instrument effects param1 param2 -> repeat, note, instrument, volume byte, fx, param, --- lost global effect (name?, param) +-- event: [0xFC repeat] note instrument effects param1 param2 local function readEvent(r: Bytes.Reader, version: number): (number, number, number, number, number, number, string?, number) local rep = 1 local b = r:u8() @@ -297,7 +291,6 @@ function Ult.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) end -- ------------------------------------------------------------------------------------------------ open --- open(r, opts) -> the module rendered as an audio Decoder (opts: Tracker.RenderOptions + DecodeOptions) function Ult.open(r: Bytes.Reader, opts: any?): (Types.Decoder?, Err.Err?) local m, err = Ult.decode(r, opts) if not m then diff --git a/src/Rosetta/music/umx/init.luau b/src/Rosetta/music/umx/init.luau index 6f3f971..82c172b 100644 --- a/src/Rosetta/music/umx/init.luau +++ b/src/Rosetta/music/umx/init.luau @@ -1,12 +1,7 @@ --!strict --- music/umx: Unreal music packages (.umx, Unreal / Unreal Tournament / Deus Ex era Unreal Engine 1 packages; package --- versions up to 128). Ported from OpenMPT's UMXTools.cpp / ContainerUMX.cpp (BSD, licenses/openmpt-LICENSE.txt): --- reads the package's name, import and export tables, finds the exports of class "music" and unwraps the module each --- one embeds (IT, S3M, XM or MOD, kept as it is). A format never requires another one, so decode hands the first --- module's bytes to opts.decodeModule (the api passes it: F.load / F.music.load sniff and load the inner module) and --- returns that Module with meta.container = { format = "umx", name, version }; without the hook decode is --- Err.UNSUPPORTED. Umx.extract(r) lists every embedded module without decoding it. --- Not supported: Unreal Engine 2+ packages (sounds, .uax), writing. +-- music/umx: Unreal Engine 1 music packages (.umx, versions up to 128), ported from OpenMPT's UMXTools.cpp / +-- ContainerUMX.cpp (BSD, licenses/openmpt-LICENSE.txt): the IT / S3M / XM / MOD module of a "music" export; decode +-- needs opts.decodeModule (the api passes it). Not supported: Unreal Engine 2+ packages (.uax), writing. -- ------------------------------------------------------------------------------------------------ requires local Err = require("@rosetta/core/Err") @@ -25,8 +20,8 @@ local Umx = { } export type DecodeOptions = { - decodeModule: ((buf: buffer, format: string?) -> (any, Err.Err?))?, -- loads the inner module (the api passes it) - index: number?, -- which music export to load (1-based, default 1) + decodeModule: ((buf: buffer, format: string?) -> (any, Err.Err?))?, + index: number?, -- 1-based, default 1 } export type Entry = { name: string, data: buffer, format: string? } @@ -104,8 +99,6 @@ function Umx.sniff(r: Bytes.Reader): number end -- ------------------------------------------------------------------------------------------------ decode --- extract(r) -> { { name, data, format? } } | nil, Err: every module embedded in the package's music exports (format: --- a guess from the inner module's signature: "it", "s3m", "xm", "mod") function Umx.extract(r: Bytes.Reader): ({ Entry }?, Err.Err?) local h = header(r) if not h then @@ -210,7 +203,6 @@ function Umx.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) end -- ------------------------------------------------------------------------------------------------ open --- open(r, opts) -> the embedded module rendered as an audio Decoder (opts: Tracker.RenderOptions + DecodeOptions) function Umx.open(r: Bytes.Reader, opts: any?): (Types.Decoder?, Err.Err?) local m, err = Umx.decode(r, opts) if not m then diff --git a/src/Rosetta/music/xm/init.luau b/src/Rosetta/music/xm/init.luau index 124701c..bc3efe3 100644 --- a/src/Rosetta/music/xm/init.luau +++ b/src/Rosetta/music/xm/init.luau @@ -1,12 +1,7 @@ --!strict --- music/xm: FastTracker 2 Extended Modules (XM 1.04, the "Extended Module: " format; also OpenMPT / MilkyTracker / --- Skale files). Written from the XM specification and FT2 behaviour notes. Reads into the codecs/audio/Tracker Module and --- plays through its engine (Module:render() / open() -> an audio Decoder): up to 32 channels (more are read), 8 / 16-bit --- delta samples, multi-sample instruments with volume / panning envelopes, fadeout and auto-vibrato, linear and Amiga --- frequency tables, every FT2 effect and volume-column command. Writes XM from "xm" modules (byte-identical for files --- in FT2's layout) and from "mod" modules (one instrument per sample, Amiga frequencies). --- ModPlug ADPCM samples decode (codecs/audio/Adpcm; written back as plain delta PCM). Not supported: OpenMPT's --- stereo-sample / extra-effect extensions on write. +-- music/xm: FastTracker 2 Extended Modules (XM 1.04), from the XM spec and FT2 behaviour notes. Supports: 8 / 16-bit +-- delta and ModPlug ADPCM samples, envelopes, linear / Amiga tables, every FT2 effect; writes "xm" (byte-identical in +-- FT2's layout) and "mod" modules. Not supported: OpenMPT's stereo-sample / extra-effect extensions on write. -- ------------------------------------------------------------------------------------------------ requires local Err = require("@rosetta/core/Err") @@ -63,7 +58,6 @@ local function makeEnvelope(xs: { number }, ys: { number }, n: number, typ: numb e.loop = bit32.band(typ, 4) ~= 0 e.susStart, e.susEnd = sus + 1, sus + 1 e.loopStart, e.loopEnd = ls + 1, le + 1 - -- the raw fields, for a faithful re-save e.raw = { type = typ, sustain = sus, loopStart = ls, loopEnd = le, count = n } return e end @@ -106,7 +100,6 @@ function Xm.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) end m.meta.tracker = tracker m.meta.source = { format = "xm", tracker = tracker, version = version } - -- patterns if not r:seek(hdrStart + hdrSize) then return nil, r.err end @@ -158,7 +151,7 @@ function Xm.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) param = pr:u8() end if pr.err then - break -- a short pattern: the rest stays empty + break end if note == 97 then note = 255 @@ -177,7 +170,6 @@ function Xm.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) end end end - -- instruments and their samples local total = 0 for i = 1, nins do local start = r:tell() @@ -186,7 +178,6 @@ function Xm.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) r:u8() local ns = r:u16le() if r.err then - -- a file cut inside the instruments: keep what was read r.err = nil break end @@ -243,8 +234,7 @@ function Xm.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) s.pan = h.pan local frames = h.len // bps if h.res == 0xAD and bits == 8 then - -- ModPlug ADPCM (codecs/audio/Adpcm): a 16-byte delta table, then 4 bits per sample; a cut file keeps - -- the samples whose nibbles are present +-- ModPlug ADPCM: a 16-byte delta table, then 4 bits per sample frames = math.max(0, math.min(h.len, (r:remaining() - 16) * 2)) total += frames * 4 if total > maxBytes then @@ -300,7 +290,6 @@ local function writeName(w: Bytes.Writer, s: string?, n: number) w:fill(0, n - #t) end --- the instruments to write: { name, samples = { sample table }, keymap = { 96 local indexes }, ins? } local function instrumentsOf(m: any): ({ any }?, string?) local out = {} if m.format == "mod" then @@ -365,7 +354,7 @@ local function envelopeFields(e: any): (number, number, number, number, number) local typ = (if e.enabled then 1 else 0) + (if e.sustain then 2 else 0) + (if e.loop then 4 else 0) local raw = e.raw if raw and raw.type % 8 == typ then - typ = raw.type -- keep unknown bits + typ = raw.type end local function idx(v: number): number return math.clamp(math.floor(v) - 1, 0, math.max(0, n - 1)) @@ -378,7 +367,6 @@ local function envelopeFields(e: any): (number, number, number, number, number) return n, typ, sus, ls, le end --- encode(module, opts) -> XM bytes ("xm" or "mod" modules) function Xm.encode(m: any, opts: EncodeOptions?): (buffer?, Err.Err?) local ok, verr = Tracker.validate(m) if not ok then @@ -479,7 +467,6 @@ function Xm.encode(m: any, opts: EncodeOptions?): (buffer?, Err.Err?) w:u16le(buffer.len(data)) w:bytes(data) end - -- instruments for _, it in insts do local ins = it.ins local smps = it.samples @@ -561,7 +548,6 @@ function Xm.encode(m: any, opts: EncodeOptions?): (buffer?, Err.Err?) end -- ------------------------------------------------------------------------------------------------ open --- open(r, opts) -> the module rendered as an audio Decoder (opts: Tracker.RenderOptions + DecodeOptions) function Xm.open(r: Bytes.Reader, opts: any?): (Types.Decoder?, Err.Err?) local m, err = Xm.decode(r, opts) if not m then diff --git a/src/Rosetta/music/xmi/init.luau b/src/Rosetta/music/xmi/init.luau index c559028..5577258 100644 --- a/src/Rosetta/music/xmi/init.luau +++ b/src/Rosetta/music/xmi/init.luau @@ -1,12 +1,7 @@ --!strict --- music/xmi: Miles Sound System XMIDI (IFF: an optional FORM XDIR with the song count, then CAT XMID of FORM XMID songs, --- or one FORM XMID; each with TIMB / RBRN chunks and the EVNT event stream). Written from the XMIDI format description --- (Miles AIL; Ryan Nunn's notes); wildmidi was used only as a reference converter in tests. Decodes one song (opts.track, --- 1-based, default 1) to a Types.Midi (format 0): interval bytes (< 0x80, summed) become absolute ticks, each note-on's --- duration becomes a note-off (velocity 64; notes still sounding at the end-of-track event end there), tempo events are dropped: XMIDI plays at a fixed 120 ticks per second --- (division 60 at 500000 us per quarter). meta.source: songs, song, timbres ({ patch, bank } from TIMB), tempo (the --- first tempo event's value, unused). Renders through codecs/audio/MidiRender. --- Not supported: writing; the RBRN branch table (kept as meta.source.branches = count); MT-32 -> GM program mapping. +-- music/xmi: Miles XMIDI (IFF: optional FORM XDIR, then CAT XMID of FORM XMID songs with TIMB / RBRN / EVNT), from +-- the XMIDI notes (Miles AIL, Ryan Nunn; wildmidi only as a test reference). Decodes one song to a Types.Midi at the +-- fixed 120 ticks per second (division 60). Not supported: writing, the RBRN branch table, MT-32 -> GM mapping. -- ------------------------------------------------------------------------------------------------ requires local Err = require("@rosetta/core/Err") @@ -45,7 +40,6 @@ local readu8 = buffer.readu8 local DATA = { [8] = 2, [9] = 2, [10] = 2, [11] = 2, [12] = 1, [13] = 1, [14] = 2 } local TYPES = { [8] = "noteOff", [9] = "noteOn", [10] = "aftertouch", [11] = "controller", [12] = "program", [13] = "channelPressure", [14] = "pitchBend" } --- a MIDI variable-length number at p -> value, next p (nil past e) local function vlq(b: buffer, p: number, e: number): (number?, number) local v = 0 for _ = 1, 4 do @@ -70,7 +64,6 @@ local function bytes(b: buffer, p: number, n: number): { number } return t end --- the EVNT stream [p, e) -> events (note-offs merged in), end tick, first tempo | nil, message local function events(b: buffer, p: number, e: number, maxEvents: number): ({ Types.MidiEvent }?, any, number?) local list: { Types.MidiEvent }, offs: { Render.PendingOff } = {}, {} local tick, tempo = 0, nil @@ -137,7 +130,6 @@ local function events(b: buffer, p: number, e: number, maxEvents: number): ({ Ty return Render.merge(list, offs), tick, tempo end --- the songs: { { evnt = Chunk, timb = Chunk? } } from the IFF tree local function songs(b: buffer, base: number, limit: number): { { [string]: Chunks.Chunk } } local out = {} local function form(c: Chunks.Chunk) @@ -203,7 +195,6 @@ function Xmi.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Midi?, Err.Er end -- ------------------------------------------------------------------------------------------------ open --- open(r, opts?) -> the rendered audio Decoder (opts: DecodeOptions + MidiRender.RenderOptions) function Xmi.open(r: Bytes.Reader, opts: any?): (Types.Decoder?, Err.Err?) local midi, err = Xmi.decode(r, opts) if not midi then