ws-audio2: bench lines for AHX / HVL render; type fixes (no new diagnostics); Types.Module format comment lists ahx / hvl
Types.luau: comment only.
This commit is contained in:
1 parent
d3ea84bb57
commit
d2c470013d
8 files changed
+39
-18
No files matched your search
@@ -138,7 +138,7 @@ Types.Audio = Audio
|
||||
export type Module = {
|
||||
kind: "music",
|
||||
title: string,
|
||||
format: string, -- "mod", "s3m", "xm", "it", "mid"
|
||||
format: string, -- "mod", "s3m", "xm", "it" (codecs/audio/Tracker); "ahx", "hvl" (codecs/audio/Hively, own render)
|
||||
channels: number,
|
||||
patterns: { any },
|
||||
order: { number },
|
||||
|
||||
@@ -66,7 +66,7 @@ function Load.parse(b: buffer, base: number, limit: number): (Tune?, string?, st
|
||||
local magic = buffer.readstring(b, base, 3)
|
||||
local ahx = magic == "THX" and u8(3) < 3
|
||||
if not ahx and not (magic == "HVL" and u8(3) <= 1) then
|
||||
return nil, "not an AHX / HVL module"
|
||||
return nil, "not an AHX / HVL module", nil
|
||||
end
|
||||
if not ahx and size < 16 then
|
||||
return nil, "truncated header", "truncated"
|
||||
@@ -94,7 +94,7 @@ function Load.parse(b: buffer, base: number, limit: number): (Tune?, string?, st
|
||||
emptyTrack0 = bit32.band(u8(6), 0x80) ~= 0,
|
||||
}
|
||||
if posn == 0 or posn > 1000 or trkl > 64 or trkl == 0 or insn > 64 then
|
||||
return nil, string.format("bad header (positions %d, track length %d, instruments %d)", posn, trkl, insn)
|
||||
return nil, string.format("bad header (positions %d, track length %d, instruments %d)", posn, trkl, insn), nil
|
||||
end
|
||||
if chnn > 16 then
|
||||
return nil, "unsupported: more than 16 channels", "unsupported"
|
||||
|
||||
@@ -668,7 +668,8 @@ local function processFrame(st: State, v: Voice)
|
||||
d3 += v.squareSign
|
||||
v.squarePos = s16(d3)
|
||||
v.plantSquare = true
|
||||
v.squareWait = if v.instrument then v.instrument.squareSpeed else 0
|
||||
local ins: any = v.instrument
|
||||
v.squareWait = if ins then ins.squareSpeed else 0
|
||||
end
|
||||
end
|
||||
|
||||
@@ -815,12 +816,9 @@ local function setAudio(st: State, v: Voice)
|
||||
v.plantPeriod = false
|
||||
v.delta = deltaOf(v.audioPeriod, st.freq)
|
||||
end
|
||||
if v.newWaveform and v.audioSrc then
|
||||
if v.waveform == 3 then
|
||||
fillCycles(v.voiceBuf, v.audioSrc, v.audioOff, 0x280)
|
||||
else
|
||||
fillCycles(v.voiceBuf, v.audioSrc, v.audioOff, 4 * 2 ^ v.waveLength)
|
||||
end
|
||||
local src: buffer? = v.audioSrc or nil
|
||||
if v.newWaveform and src then
|
||||
fillCycles(v.voiceBuf, src, v.audioOff, if v.waveform == 3 then 0x280 else 4 * 2 ^ v.waveLength)
|
||||
end
|
||||
if v.ringPlantPeriod then
|
||||
v.ringPlantPeriod = false
|
||||
|
||||
@@ -290,7 +290,7 @@ function Render.merge(events: { Types.MidiEvent }, offs: { PendingOff }): { Type
|
||||
end
|
||||
return a.seq < b.seq
|
||||
end)
|
||||
local out: { Types.MidiEvent } = table.create(#events + #offs)
|
||||
local out: { Types.MidiEvent } = table.create(#events + #offs) :: { Types.MidiEvent }
|
||||
local k = 1
|
||||
for _, ev in events do
|
||||
while k <= #offs and (offs[k].tick < ev.tick or (offs[k].tick == ev.tick and offs[k].onTick < ev.tick)) do
|
||||
|
||||
@@ -70,7 +70,7 @@ local function delta(b: buffer, p: number, e: number, hmp: boolean): (number?, n
|
||||
end
|
||||
|
||||
local function bytes(b: buffer, p: number, n: number): { number }
|
||||
local t = table.create(n)
|
||||
local t: { number } = table.create(n) :: { number }
|
||||
for i = 1, n do
|
||||
t[i] = readu8(b, p + i - 1)
|
||||
end
|
||||
@@ -176,7 +176,7 @@ local function hmpTracks(b: buffer, base: number, limit: number): ({ { number }
|
||||
local n = readu32(b, base + 0x30)
|
||||
local p = base + (if new then 0x388 else 0x308)
|
||||
if n == 0 or n > 256 then
|
||||
return nil, string.format("bad track count %d", n)
|
||||
return nil, string.format("bad track count %d", n), nil
|
||||
end
|
||||
local ranges = {}
|
||||
for _ = 1, n do
|
||||
@@ -196,7 +196,7 @@ end
|
||||
local function hmiTracks(b: buffer, base: number, limit: number): ({ { number } }?, string?, string?)
|
||||
local n = readu8(b, base + 228)
|
||||
if n == 0 then
|
||||
return nil, "no tracks"
|
||||
return nil, "no tracks", nil
|
||||
end
|
||||
if base + 370 + n * 4 > limit then
|
||||
return nil, "truncated track table", "truncated"
|
||||
@@ -205,7 +205,7 @@ local function hmiTracks(b: buffer, base: number, limit: number): ({ { number }
|
||||
for i = 0, n - 1 do
|
||||
local at = base + readu32(b, base + 370 + i * 4)
|
||||
if at < base or at + 0x5B > limit or buffer.readstring(b, at, 13) ~= "HMI-MIDITRACK" then
|
||||
return nil, string.format("bad track %d header", i)
|
||||
return nil, string.format("bad track %d header", i), nil
|
||||
end
|
||||
local start = at + readu32(b, at + 0x57)
|
||||
if start >= limit then
|
||||
|
||||
@@ -84,7 +84,7 @@ local function karaoke(midi: Types.Midi)
|
||||
if #lyrics == 0 and next(headers) == nil then
|
||||
return
|
||||
end
|
||||
table.sort(lyrics, function(a, b): boolean
|
||||
table.sort(lyrics, function(a: { time: number, tick: number, text: string }, b: { time: number, tick: number, text: string }): boolean
|
||||
return a.time < b.time
|
||||
end)
|
||||
midi.meta.lyrics = lyrics
|
||||
|
||||
@@ -63,7 +63,7 @@ local function vlq(b: buffer, p: number, e: number): (number?, number)
|
||||
end
|
||||
|
||||
local function bytes(b: buffer, p: number, n: number): { number }
|
||||
local t = table.create(n)
|
||||
local t: { number } = table.create(n) :: { number }
|
||||
for i = 1, n do
|
||||
t[i] = readu8(b, p + i - 1)
|
||||
end
|
||||
@@ -192,10 +192,12 @@ function Xmi.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Midi?, Err.Er
|
||||
table.insert(timbres, { patch = readu8(r.buf, tb.offset + 2 + i * 2), bank = readu8(r.buf, tb.offset + 3 + i * 2) })
|
||||
end
|
||||
end
|
||||
local rb = song.RBRN
|
||||
local branches = if rb and rb.avail >= 2 then buffer.readu16(r.buf, rb.offset) else 0
|
||||
local midi = Types.Midi.new(60)
|
||||
midi.format = 0
|
||||
midi.tracks = { { events = evs } }
|
||||
Render.attach(midi, { format = "xmi", songs = #list, song = index, timbres = timbres, tempo = tempo, branches = if song.RBRN and song.RBRN.avail >= 2 then buffer.readu16(r.buf, song.RBRN.offset) else 0 })
|
||||
Render.attach(midi, { format = "xmi", songs = #list, song = index, timbres = timbres, tempo = tempo, branches = branches })
|
||||
midi.meta.truncated = ev.truncated
|
||||
return midi, nil
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user