codecs/audio: comments to specs only

This commit is contained in:
4DBug committed 2026-11-01 01:55:39 -05:00
1 parent 0bd7b87d2b
commit 6dcce481bb
69 files changed
+523 -1604

No files matched your search

+9 -24
View File
@@ -1,10 +1,7 @@
--!strict
-- codecs/audio/Tracker/Load: helpers shared by the tracker loaders that map another format's effects onto one of the
-- engine's families (music/mtm, 669, stm, ult, okt, med, ptm, far). Effects are first named the way OpenMPT's loaders
-- name them ("portaup", "volslide", "modex", ...), then written in the family's own cell coding: S3M / IT letter
-- codes (A = 1) with the IT volume column, or MOD / XM numbers. Ported from OpenMPT's ModCommand helpers
-- (ConvertModCommand, ConvertToVolCommand, FillInTwoCommands, GetEffectWeight, CPattern::WriteEffect; BSD licence,
-- licenses/openmpt-LICENSE.txt), reduced to what the engine plays.
-- codecs/audio/Tracker/Load: helpers mapping other tracker formats' effects onto the engine's S3M / IT or MOD / XM families.
-- Ported from OpenMPT's ModCommand helpers (ConvertModCommand, ConvertToVolCommand, FillInTwoCommands, GetEffectWeight,
-- CPattern::WriteEffect; BSD licence, licenses/openmpt-LICENSE.txt).
local Err = require("@rosetta/core/Err")
local Player = require("@rosetta/codecs/audio/Tracker/Player")
local Pcm = require("@rosetta/codecs/audio/Tracker/Pcm")
@@ -14,7 +11,6 @@ local Load = {}
local EXT = Player.EXT
-- the S3M / IT letter code of each effect name (engine extension effects included)
local IT: { [string]: number } = {
speed = 1,
jump = 2,
@@ -67,7 +63,7 @@ end
local GLOBAL = { jump = true, ["break"] = true, speed = true, tempo = true, globalvol = true, globalvolslide = true }
-- isGlobal(name, param) -> the effect acts on the whole song (OpenMPT's IsGlobalCommand)
-- OpenMPT's IsGlobalCommand
function Load.isGlobal(name: string?, param: number): boolean
if name == nil then
return false
@@ -84,7 +80,7 @@ function Load.isGlobal(name: string?, param: number): boolean
return false
end
-- modCommand(cmd, param) -> name?, param: a MOD / XM effect number (0..F, XM letters 16..) by name (ConvertModCommand)
-- OpenMPT's ConvertModCommand
local MODFX: { [number]: string } = {
[0] = "arpeggio", [1] = "portaup", [2] = "portadown", [3] = "toneporta", [4] = "vibrato", [5] = "toneportavol",
[6] = "vibratovol", [7] = "tremolo", [8] = "panning8", [9] = "offset", [10] = "volslide", [11] = "jump",
@@ -104,8 +100,7 @@ function Load.modCommand(cmd: number, param: number): (string?, number)
return n, param
end
-- itVolume(name, param, force) -> the IT volume-column byte + 1 (the engine's coding) for an effect that fits there,
-- or nil (OpenMPT's ConvertToVolCommand; force: fit it with some loss of precision)
-- OpenMPT's ConvertToVolCommand (force: fit with some loss of precision)
function Load.itVolume(name: string?, param: number, force: boolean): number?
if name == "volume" then
return math.min(param, 64) + 1
@@ -159,8 +154,6 @@ function Load.itVolume(name: string?, param: number, force: boolean): number?
return nil
end
-- itEffect(name, param) -> effect code, param in S3M / IT coding (0, 0 for none or an effect the family lacks; MOD's
-- extended E commands become their S3M equivalents)
function Load.itEffect(name: string?, param: number): (number, number)
if name == nil then
return 0, 0
@@ -191,9 +184,7 @@ function Load.itEffect(name: string?, param: number): (number, number)
return code, param
end
-- fillTwo(name1, param1, name2, param2, lowResOffset?) -> volume byte (engine IT coding, 0 none), effect name, param,
-- lost name?, lost param: two effects of one cell into the IT volume column and the effect column, keeping the
-- heavier one when both cannot fit (OpenMPT's FillInTwoCommands)
-- OpenMPT's FillInTwoCommands
function Load.fillTwo(e1: string?, p1: number, e2: string?, p2: number): (number, string?, number, string?, number)
if e1 ~= nil and e1 == e2 then
e2 = nil -- the same effect twice: keep one (most are absolute; slides are kept once too, a simplification)
@@ -215,10 +206,7 @@ function Load.fillTwo(e1: string?, p1: number, e2: string?, p2: number): (number
return 0, e2, p2, e1, p1
end
-- writeEffect(m, pattern (0-based), row, fx, param, retry?, channel?, multiple?) -> true when written: puts an effect
-- into a free effect slot of the row (any channel, or the given 1-based one); none free: the next row (retry "next") or
-- the previous one ("prev"). The same effect already on the row counts as written unless multiple (OpenMPT's
-- CPattern::WriteEffect).
-- OpenMPT's CPattern::WriteEffect
function Load.writeEffect(m: any, pattern: number, row: number, fx: number, param: number, retry: string?, channel: number?, multiple: boolean?): boolean
local p = m.patterns[pattern + 1]
if not p then
@@ -261,9 +249,6 @@ function Load.writeEffect(m: any, pattern: number, row: number, fx: number, para
return false
end
-- readSample(buf, offset, frames, spec, sample, budget) -> true | nil, Err: decodes raw PCM (codecs/audio/Tracker/Pcm
-- spec) at the absolute buffer offset into the sample (data, length, bits, channels). A short file keeps the frames
-- that are there (end = the buffer's length, or spec.limit). budget = { left = f32 bytes still allowed } (maxBytes).
function Load.readSample(buf: buffer, offset: number, frames: number, spec: any, s: any, budget: { left: number }): (boolean?, Err.Err?)
local nch = spec.channels or 1
local bps = spec.bits // 8
@@ -282,7 +267,7 @@ function Load.readSample(buf: buffer, offset: number, frames: number, spec: any,
return true, nil
end
-- bcd(n) -> n as the two decimal digits S3M / MOD pattern breaks store (0..99)
-- S3M / MOD pattern breaks store the row as two decimal digits
function Load.bcd(n: number): number
n = math.clamp(math.floor(n), 0, 99)
return (n // 10) * 16 + n % 10