51 lines
2.1 KiB
Luau
51 lines
2.1 KiB
Luau
--!strict
|
|
--!optimize 2
|
|
-- 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")
|
|
local Bytes = require("@rosetta/core/Bytes")
|
|
local Types = require("@rosetta/Types")
|
|
local Hively = require("@rosetta/codecs/audio/Hively")
|
|
|
|
-- ------------------------------------------------------------------------------------------------ contract
|
|
local Hvl = {
|
|
name = "hvl",
|
|
category = "music",
|
|
extensions = { "hvl" },
|
|
mime = { "audio/x-hvl" },
|
|
deps = { "core/Err", "core/Bytes", "Types", "codecs/audio/Hively" },
|
|
caps = { decode = true, encode = false, render = true, channels = { 4, 16 }, subsongs = true },
|
|
}
|
|
|
|
-- ------------------------------------------------------------------------------------------------ types
|
|
export type RenderOptions = Hively.RenderOptions -- stereo comes from the file
|
|
|
|
-- ------------------------------------------------------------------------------------------------ sniff
|
|
function Hvl.sniff(r: Bytes.Reader): number
|
|
local m = r:peek(4)
|
|
return if m and #m == 4 and string.sub(m, 1, 3) == "HVL" and string.byte(m, 4) <= 1 then 1 else 0
|
|
end
|
|
|
|
-- ------------------------------------------------------------------------------------------------ decode
|
|
function Hvl.decode(r: Bytes.Reader, _opts: any?): (Types.Module?, Err.Err?)
|
|
local tune, err = Hively.parse(r.buf, r.base, r.limit)
|
|
if not tune or tune.format ~= "hvl" then
|
|
return nil, err or Err.new(Err.CORRUPT, "not an HVL module")
|
|
end
|
|
return Hively.module(tune), nil
|
|
end
|
|
|
|
-- ------------------------------------------------------------------------------------------------ open
|
|
function Hvl.open(r: Bytes.Reader, opts: RenderOptions?): (Types.Decoder?, Err.Err?)
|
|
local song, err = Hvl.decode(r)
|
|
if not song then
|
|
return nil, err
|
|
end
|
|
return Hively.decoder((song :: any).tune, opts)
|
|
end
|
|
|
|
return Hvl
|