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 = {
|
export type Module = {
|
||||||
kind: "music",
|
kind: "music",
|
||||||
title: string,
|
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,
|
channels: number,
|
||||||
patterns: { any },
|
patterns: { any },
|
||||||
order: { number },
|
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 magic = buffer.readstring(b, base, 3)
|
||||||
local ahx = magic == "THX" and u8(3) < 3
|
local ahx = magic == "THX" and u8(3) < 3
|
||||||
if not ahx and not (magic == "HVL" and u8(3) <= 1) then
|
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
|
end
|
||||||
if not ahx and size < 16 then
|
if not ahx and size < 16 then
|
||||||
return nil, "truncated header", "truncated"
|
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,
|
emptyTrack0 = bit32.band(u8(6), 0x80) ~= 0,
|
||||||
}
|
}
|
||||||
if posn == 0 or posn > 1000 or trkl > 64 or trkl == 0 or insn > 64 then
|
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
|
end
|
||||||
if chnn > 16 then
|
if chnn > 16 then
|
||||||
return nil, "unsupported: more than 16 channels", "unsupported"
|
return nil, "unsupported: more than 16 channels", "unsupported"
|
||||||
|
|||||||
@@ -668,7 +668,8 @@ local function processFrame(st: State, v: Voice)
|
|||||||
d3 += v.squareSign
|
d3 += v.squareSign
|
||||||
v.squarePos = s16(d3)
|
v.squarePos = s16(d3)
|
||||||
v.plantSquare = true
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -815,12 +816,9 @@ local function setAudio(st: State, v: Voice)
|
|||||||
v.plantPeriod = false
|
v.plantPeriod = false
|
||||||
v.delta = deltaOf(v.audioPeriod, st.freq)
|
v.delta = deltaOf(v.audioPeriod, st.freq)
|
||||||
end
|
end
|
||||||
if v.newWaveform and v.audioSrc then
|
local src: buffer? = v.audioSrc or nil
|
||||||
if v.waveform == 3 then
|
if v.newWaveform and src then
|
||||||
fillCycles(v.voiceBuf, v.audioSrc, v.audioOff, 0x280)
|
fillCycles(v.voiceBuf, src, v.audioOff, if v.waveform == 3 then 0x280 else 4 * 2 ^ v.waveLength)
|
||||||
else
|
|
||||||
fillCycles(v.voiceBuf, v.audioSrc, v.audioOff, 4 * 2 ^ v.waveLength)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if v.ringPlantPeriod then
|
if v.ringPlantPeriod then
|
||||||
v.ringPlantPeriod = false
|
v.ringPlantPeriod = false
|
||||||
|
|||||||
@@ -290,7 +290,7 @@ function Render.merge(events: { Types.MidiEvent }, offs: { PendingOff }): { Type
|
|||||||
end
|
end
|
||||||
return a.seq < b.seq
|
return a.seq < b.seq
|
||||||
end)
|
end)
|
||||||
local out: { Types.MidiEvent } = table.create(#events + #offs)
|
local out: { Types.MidiEvent } = table.create(#events + #offs) :: { Types.MidiEvent }
|
||||||
local k = 1
|
local k = 1
|
||||||
for _, ev in events do
|
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
|
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
|
end
|
||||||
|
|
||||||
local function bytes(b: buffer, p: number, n: number): { number }
|
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
|
for i = 1, n do
|
||||||
t[i] = readu8(b, p + i - 1)
|
t[i] = readu8(b, p + i - 1)
|
||||||
end
|
end
|
||||||
@@ -176,7 +176,7 @@ local function hmpTracks(b: buffer, base: number, limit: number): ({ { number }
|
|||||||
local n = readu32(b, base + 0x30)
|
local n = readu32(b, base + 0x30)
|
||||||
local p = base + (if new then 0x388 else 0x308)
|
local p = base + (if new then 0x388 else 0x308)
|
||||||
if n == 0 or n > 256 then
|
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
|
end
|
||||||
local ranges = {}
|
local ranges = {}
|
||||||
for _ = 1, n do
|
for _ = 1, n do
|
||||||
@@ -196,7 +196,7 @@ end
|
|||||||
local function hmiTracks(b: buffer, base: number, limit: number): ({ { number } }?, string?, string?)
|
local function hmiTracks(b: buffer, base: number, limit: number): ({ { number } }?, string?, string?)
|
||||||
local n = readu8(b, base + 228)
|
local n = readu8(b, base + 228)
|
||||||
if n == 0 then
|
if n == 0 then
|
||||||
return nil, "no tracks"
|
return nil, "no tracks", nil
|
||||||
end
|
end
|
||||||
if base + 370 + n * 4 > limit then
|
if base + 370 + n * 4 > limit then
|
||||||
return nil, "truncated track table", "truncated"
|
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
|
for i = 0, n - 1 do
|
||||||
local at = base + readu32(b, base + 370 + i * 4)
|
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
|
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
|
end
|
||||||
local start = at + readu32(b, at + 0x57)
|
local start = at + readu32(b, at + 0x57)
|
||||||
if start >= limit then
|
if start >= limit then
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ local function karaoke(midi: Types.Midi)
|
|||||||
if #lyrics == 0 and next(headers) == nil then
|
if #lyrics == 0 and next(headers) == nil then
|
||||||
return
|
return
|
||||||
end
|
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
|
return a.time < b.time
|
||||||
end)
|
end)
|
||||||
midi.meta.lyrics = lyrics
|
midi.meta.lyrics = lyrics
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ local function vlq(b: buffer, p: number, e: number): (number?, number)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function bytes(b: buffer, p: number, n: number): { number }
|
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
|
for i = 1, n do
|
||||||
t[i] = readu8(b, p + i - 1)
|
t[i] = readu8(b, p + i - 1)
|
||||||
end
|
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) })
|
table.insert(timbres, { patch = readu8(r.buf, tb.offset + 2 + i * 2), bank = readu8(r.buf, tb.offset + 3 + i * 2) })
|
||||||
end
|
end
|
||||||
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)
|
local midi = Types.Midi.new(60)
|
||||||
midi.format = 0
|
midi.format = 0
|
||||||
midi.tracks = { { events = evs } }
|
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
|
midi.meta.truncated = ev.truncated
|
||||||
return midi, nil
|
return midi, nil
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1078,3 +1078,24 @@ do
|
|||||||
jitTune(false)
|
jitTune(false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
-- ws-audio2: chip/midi
|
||||||
|
do
|
||||||
|
-- AHX / HVL (codecs/audio/Hively): a whole song rendered at 44.1 kHz (tools/fixtures/ahx.py karma.ahx, 3 s; hvl.py
|
||||||
|
-- the 6-channel demo with ring modulation); MB/s of stereo f32 output, and how many times faster than real time
|
||||||
|
local Ahx, Hvl = require("@formats/music/ahx"), require("@formats/music/hvl")
|
||||||
|
local AC, HC = require("@tests/gen/ahx_cases"), require("@tests/gen/hvl_cases")
|
||||||
|
for _, spec in { { Ahx, AC, "karma.ahx", "ahx render karma (4 ch)" }, { Hvl, HC, "demo", "hvl render demo (6 ch)" } } do
|
||||||
|
for _, c in spec[2] do
|
||||||
|
if c.name == spec[3] then
|
||||||
|
local song = assert(spec[1].decode(Bytes.reader(buffer.fromstring(c.data))))
|
||||||
|
local frames = 0
|
||||||
|
local dt = bench(spec[4], 3, c.frames * 8, function()
|
||||||
|
local dec = song:render({ maxDuration = c.maxDuration })
|
||||||
|
frames = dec.frames
|
||||||
|
dec:read(frames)
|
||||||
|
end)
|
||||||
|
print(string.format("%-8s %-30s %8.1f x real time", runtime, "", frames / 44100 / dt))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in new issue
Block a user