ws-audio2: AHX and HVL (music/ahx, music/hvl) over codecs/audio/Hively, a port of hvl2wav's replay.c (BSD-3): bit-exact vs hvl2wav
This commit is contained in:
1 parent
4dd6cd1400
commit
848e4bfff6
16 files changed
+2274
No files matched your search
@@ -0,0 +1,45 @@
|
||||
-- tests/music/_hively: shared helper of the AHX / HVL tests (not a test itself): renders a fixture case through the
|
||||
-- format and compares it with hvl2wav's output exactly (16-bit samples: CRC-32 of the whole stream, the first
|
||||
-- differing frame located inside the raw head kept by tools/fixtures/ahx.py / hvl.py).
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
|
||||
local H = {}
|
||||
|
||||
-- check(t, Format, c): decode + render + exact comparison; returns the song
|
||||
function H.check(t: any, Format: any, c: any): any
|
||||
local song, err = Format.decode(Bytes.reader(buffer.fromstring(c.data)))
|
||||
t:check(song, c.name .. ": " .. tostring(err))
|
||||
if not song then
|
||||
return nil
|
||||
end
|
||||
t:check(Format.sniff(Bytes.reader(buffer.fromstring(c.data))) == 1, c.name .. ": sniff")
|
||||
local dec = song:render({ sampleRate = c.sampleRate, stereo = c.stereo, subsong = c.subsong, maxDuration = c.maxDuration })
|
||||
t:check(dec.err == nil, c.name .. ": render " .. tostring(dec.err))
|
||||
local frames = if c.prefix then math.min(dec.frames, c.frames) else dec.frames
|
||||
if not c.prefix then
|
||||
t:eq(dec.frames, c.frames, c.name .. ": frames (song end as hvl2wav finds it)")
|
||||
end
|
||||
local f32 = dec:read(frames)
|
||||
local s16 = buffer.create(frames * 4)
|
||||
for i = 0, frames * 2 - 1 do
|
||||
buffer.writei16(s16, i * 2, math.floor(buffer.readf32(f32, i * 4) * 32768 + 0.5))
|
||||
end
|
||||
-- (a time-limited reference whose song ends earlier than the limit: only the head can be compared)
|
||||
local exact = (frames == c.frames and Crc32.of(s16) == c.crc) or (c.prefix and frames < c.frames)
|
||||
local head = buffer.fromstring(c.head)
|
||||
local firstDiff = -1
|
||||
for i = 0, math.min(frames, buffer.len(head) // 4) * 2 - 1 do
|
||||
if buffer.readi16(s16, i * 2) ~= buffer.readi16(head, i * 2) then
|
||||
firstDiff = i // 2
|
||||
break
|
||||
end
|
||||
end
|
||||
t:check(firstDiff < 0, string.format("%s: first differing frame %d (ours %d, hvl2wav %d)", c.name, firstDiff,
|
||||
if firstDiff >= 0 then buffer.readi16(s16, firstDiff * 4) else 0, if firstDiff >= 0 then buffer.readi16(head, firstDiff * 4) else 0))
|
||||
t:check(exact, c.name .. ": samples equal hvl2wav's (CRC-32 of " .. frames .. " frames)")
|
||||
t:note("%-22s %6d frames %s", c.name, frames, if exact and firstDiff < 0 then "bit-exact vs hvl2wav" else "DIFFERS")
|
||||
return song
|
||||
end
|
||||
|
||||
return H
|
||||
@@ -0,0 +1,68 @@
|
||||
-- music/ahx tests: AHX songs written by tools/fixtures/_hively.py (every waveform, filter and square sweeps, PList
|
||||
-- commands, effects, subsongs, AHX versions 0..2) and karma.ahx from the HivelyTracker source, rendered through
|
||||
-- codecs/audio/Hively and compared sample for sample with hvl2wav at several stereo separations and rates; the Module
|
||||
-- shape, bad input, and the fuzz no-throw pass. Fixtures: tools/fixtures/ahx.py.
|
||||
local T = require("@tests/T")
|
||||
local H = require("@tests/music/_hively")
|
||||
local Ahx = require("@formats/music/ahx")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Cases = require("@tests/gen/ahx_cases")
|
||||
|
||||
local t = T.suite("ahx")
|
||||
|
||||
t:eq(Ahx.name, "ahx", "name")
|
||||
t:eq(Ahx.category, "music", "category")
|
||||
t:check(Ahx.caps.decode and not Ahx.caps.encode, "caps")
|
||||
t:eq(Ahx.sniff(Bytes.reader(buffer.fromstring("HVL\1"))), 0, "sniff HVL")
|
||||
|
||||
local samples = {}
|
||||
for _, c in Cases do
|
||||
local song = H.check(t, Ahx, c)
|
||||
if song and c.name == "demo" then
|
||||
t:eq(song.kind, "music", "kind")
|
||||
t:eq(song.format, "ahx", "format")
|
||||
t:eq(song.title, "demo", "title")
|
||||
t:eq(song.channels, 4, "channels")
|
||||
t:eq(#song.order, 2, "positions")
|
||||
t:eq(song.instruments[1].name, "tri", "instrument name")
|
||||
t:eq(#song.instruments[3].plist.entries, 4, "play list")
|
||||
t:eq(song.patterns[2].rows, 16, "track rows")
|
||||
t:eq(buffer.readu8(song.patterns[2].data, 0), 25, "track 1 row 0 note")
|
||||
t:eq(#song.subsongs, 1, "subsongs")
|
||||
-- seek back and read again: the same samples
|
||||
local dec = song:render()
|
||||
local a = dec:read(4410)
|
||||
dec:seek(0.5)
|
||||
dec:seek(0)
|
||||
local b = dec:read(4410)
|
||||
t:check(buffer.tostring(a) == buffer.tostring(b), "seek restarts exactly")
|
||||
end
|
||||
if #samples < 4 then
|
||||
table.insert(samples, buffer.fromstring(c.data))
|
||||
end
|
||||
end
|
||||
|
||||
-- bad input
|
||||
local function code(s: string): string?
|
||||
local _, e = Ahx.decode(Bytes.reader(buffer.fromstring(s)))
|
||||
return e and e.code
|
||||
end
|
||||
t:eq(code("THX"), Err.TRUNCATED, "short header")
|
||||
t:eq(code("THX\1\0\14\0\0\0\0\16\0\0\0"), Err.CORRUPT, "no positions")
|
||||
t:eq(code(string.sub(Cases[1].data, 1, 60)), Err.TRUNCATED, "truncated")
|
||||
local song = assert(Ahx.decode(Bytes.reader(buffer.fromstring(Cases[1].data))))
|
||||
t:check(song:render({ subsong = 9 }).err ~= nil, "subsong out of range")
|
||||
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Ahx.decode(Bytes.reader(b))
|
||||
end, samples)
|
||||
t:fuzz("decode + render", function(b: buffer)
|
||||
local s = Ahx.decode(Bytes.reader(b))
|
||||
if s then
|
||||
local d = s:render({ sampleRate = 8000, maxDuration = 0.5 })
|
||||
d:read(4000)
|
||||
end
|
||||
return s
|
||||
end, samples, { mutations = 150, garbage = 20 })
|
||||
t:done()
|
||||
@@ -0,0 +1,71 @@
|
||||
-- music/hvl tests: HVL songs written by tools/fixtures/_hively.py (4..8 channels, two effect columns, ring modulation,
|
||||
-- panning, mix gain / stereo from the file, subsongs) and songs from the HivelyTracker source, rendered through
|
||||
-- codecs/audio/Hively and compared sample for sample with hvl2wav (44.1 and 48 kHz); the Module shape, bad input, and
|
||||
-- the fuzz no-throw pass. Fixtures: tools/fixtures/hvl.py.
|
||||
local T = require("@tests/T")
|
||||
local H = require("@tests/music/_hively")
|
||||
local Hvl = require("@formats/music/hvl")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Cases = require("@tests/gen/hvl_cases")
|
||||
|
||||
local t = T.suite("hvl")
|
||||
|
||||
t:eq(Hvl.name, "hvl", "name")
|
||||
t:eq(Hvl.category, "music", "category")
|
||||
t:check(Hvl.caps.decode and not Hvl.caps.encode, "caps")
|
||||
t:eq(Hvl.sniff(Bytes.reader(buffer.fromstring("THX\1"))), 0, "sniff AHX")
|
||||
|
||||
local samples = {}
|
||||
for _, c in Cases do
|
||||
local song = H.check(t, Hvl, c)
|
||||
if song and c.name == "demo" then
|
||||
t:eq(song.kind, "music", "kind")
|
||||
t:eq(song.format, "hvl", "format")
|
||||
t:eq(song.title, "demo", "title")
|
||||
t:eq(song.channels, 6, "channels")
|
||||
t:eq(song.meta.source.stereo, 3, "stereo")
|
||||
t:eq(#song.instruments, 6, "instruments")
|
||||
t:eq(#song.order, 2, "positions")
|
||||
t:eq(song.instruments[1].name, "tri", "instrument name")
|
||||
t:eq(#song.instruments[3].plist.entries, 4, "play list")
|
||||
t:eq(song.patterns[2].rows, 16, "track rows")
|
||||
t:eq(buffer.readu8(song.patterns[2].data, 0), 25, "track 1 row 0 note")
|
||||
t:eq(#song.subsongs, 1, "subsongs")
|
||||
-- seek back and read again: the same samples
|
||||
local dec = song:render()
|
||||
local a = dec:read(4410)
|
||||
dec:seek(0.5)
|
||||
dec:seek(0)
|
||||
local b = dec:read(4410)
|
||||
t:check(buffer.tostring(a) == buffer.tostring(b), "seek restarts exactly")
|
||||
end
|
||||
if #samples < 4 then
|
||||
table.insert(samples, buffer.fromstring(c.data))
|
||||
end
|
||||
end
|
||||
|
||||
-- bad input
|
||||
local function code(s: string): string?
|
||||
local _, e = Hvl.decode(Bytes.reader(buffer.fromstring(s)))
|
||||
return e and e.code
|
||||
end
|
||||
t:eq(code("HVL\1\0\16\0\1\0"), Err.TRUNCATED, "short header")
|
||||
t:eq(code("HVL\1\0\16\0\0\0\0\16\0\0\0\100\2"), Err.CORRUPT, "no positions")
|
||||
t:eq(code("HVL\1\0\16\0\1\255\0\16\0\0\0\100\2"), Err.UNSUPPORTED, "67 channels")
|
||||
t:eq(code(string.sub(Cases[1].data, 1, 60)), Err.TRUNCATED, "truncated")
|
||||
local song = assert(Hvl.decode(Bytes.reader(buffer.fromstring(Cases[1].data))))
|
||||
t:check(song:render({ subsong = 9 }).err ~= nil, "subsong out of range")
|
||||
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Hvl.decode(Bytes.reader(b))
|
||||
end, samples)
|
||||
t:fuzz("decode + render", function(b: buffer)
|
||||
local s = Hvl.decode(Bytes.reader(b))
|
||||
if s then
|
||||
local d = s:render({ sampleRate = 8000, maxDuration = 0.5 })
|
||||
d:read(4000)
|
||||
end
|
||||
return s
|
||||
end, samples, { mutations = 150, garbage = 20 })
|
||||
t:done()
|
||||
Reference in new issue
Block a user