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,17 +1,8 @@
--!strict
-- codecs/audio/Hively: the AHX / HivelyTracker engine behind music/ahx and music/hvl: the loader for both file formats
-- (Load), the replayer with its waveform generator (Tables: triangle / sawtooth / square / noise and the 31 + 31
-- filtered copies) and integer mixer (Player), and the render glue to a Types.Decoder (stereo f32). A port of
-- HivelyTracker's hvl2wav replay.c 1.9 (BSD-3-Clause, (c) 2006-2018 Pete Gordon; licenses/hivelytracker-LICENSE.txt):
-- at hvl2wav's settings the output equals hvl2wav's 16-bit samples / 32768, sample for sample.
--
-- local Hively = require("@rosetta/codecs/audio/Hively")
-- local tune, err = Hively.parse(buf, 0, buffer.len(buf)) -- the replayer's Tune
-- local song = Hively.module(tune) -- a Types.Module-shaped value with render()
-- local dec = Hively.decoder(tune, { sampleRate = 44100 }) -- a Types.Decoder
--
-- Not supported: hvl2wav's -a auto gain; a speed multiplier of 4 at 44.1 kHz renders 880 samples per 50 Hz frame
-- (hvl2wav pads each frame to 882 with stale samples).
-- codecs/audio/Hively: the AHX / HivelyTracker engine (loader, replayer, waveform tables, render glue).
-- A port of hvl2wav replay.c 1.9 (BSD-3-Clause, (c) 2006-2018 Pete Gordon; licenses/hivelytracker-LICENSE.txt); at
-- hvl2wav's settings the output equals its 16-bit samples / 32768. hvl2wav pads a 44.1 kHz speed-multiplier-4 frame to
-- 882 samples with stale data; this renders 880.
local Err = require("@rosetta/core/Err")
local Types = require("@rosetta/Types")
local Load = require("@rosetta/codecs/audio/Hively/Load")
@@ -22,14 +13,13 @@ local Hively = {}
export type Tune = Load.Tune
export type RenderOptions = {
sampleRate: number?, -- default 44100 (the replayer runs at any rate: 8000..192000)
subsong: number?, -- 0 = the main song (default), 1..n the subsongs
stereo: number?, -- AHX stereo separation 0..4 (0 mono, 4 = 100 % Amiga L R R L); default 0 as hvl2wav. HVL: the file's
loop: boolean?, -- keep playing past the song end (frames / duration still give one pass)
sampleRate: number?,
subsong: number?,
stereo: number?, -- AHX stereo separation 0..4 (4 = 100 % Amiga L R R L); default 0 as hvl2wav
loop: boolean?,
maxDuration: number?, -- seconds, default 600 (hvl2wav's 10 minute limit)
}
-- parse(b, base?, limit?) -> Tune | nil, Err
function Hively.parse(b: buffer, base: number?, limit: number?): (Tune?, Err.Err?)
local tune, msg, kind = Load.parse(b, base or 0, limit or buffer.len(b))
if not tune then
@@ -51,7 +41,6 @@ local function settings(tune: Tune, opts: RenderOptions?): (number?, number, num
return rate, sub, tonumber(o.stereo) or 0, nil
end
-- frameCount(tune, opts?) -> 50 Hz frames until the song end (as hvl2wav stops), capped by maxDuration
function Hively.frameCount(tune: Tune, opts: RenderOptions?): number
local rate, sub, stereo = settings(tune, opts)
local st = rate and Player.new(tune, rate :: number, stereo, sub)
@@ -69,7 +58,6 @@ function Hively.frameCount(tune: Tune, opts: RenderOptions?): number
return n
end
-- decoder(tune, opts?) -> Types.Decoder | nil, Err
function Hively.decoder(tune: Tune, opts: RenderOptions?): (Types.Decoder?, Err.Err?)
local rate, sub, stereo, err = settings(tune, opts)
if not rate then
@@ -84,7 +72,7 @@ function Hively.decoder(tune: Tune, opts: RenderOptions?): (Types.Decoder?, Err.
local loop = opts ~= nil and opts.loop == true
local st = Player.new(tune, sr, stereo, sub) :: Player.State
local fbuf = buffer.create(perFrame * 8)
local fpos, ffill = 0, 0 -- read position / filled frames inside fbuf
local fpos, ffill = 0, 0
local pos = 0
local function nextFrame()
@@ -147,8 +135,6 @@ function Hively.decoder(tune: Tune, opts: RenderOptions?): (Types.Decoder?, Err.
return (dec :: any) :: Types.Decoder, nil
end
-- module(tune) -> a Types.Module-shaped value (kind "music"): tracks as patterns (rows * 6 bytes: note, instrument,
-- fx, param, fxb, paramb), positions, instruments with their play lists, and render(opts) -> Decoder
function Hively.module(tune: Tune): Types.Module
local patterns = {}
for t = 0, tune.trackNr do
@@ -198,7 +184,6 @@ function Hively.module(tune: Tune): Types.Module
if dec then
return dec
end
-- the Types contract returns a Decoder: a failed render is an empty one carrying the Err
local empty: any = Pcm.audioDecoder(Types.Audio.new(44100, 2, 0))
empty.err = derr
return empty