tests/ops: comments: specs only

This commit is contained in:
4DBug committed 2026-11-01 01:51:09 -05:00
1 parent 9d80ee11b9
commit 75ddfb4068
5 files changed
+7 -58

No files matched your search

+1 -10
View File
@@ -1,6 +1,4 @@
-- ops/AudioOps tests: toAudio from a Decoder, gain / gainDb / normalize, peak / RMS of known signals, remix matrices -- ops/AudioOps tests on known signals.
-- (5.1 -> stereo -> mono, mono -> stereo / 5.1), resample through codecs/audio/Resample, trim, concat and mix with rate /
-- channel conversion, fades, bad arguments (Err.ARG, never a throw), and the F.ops facade.
local T = require("@tests/T") local T = require("@tests/T")
local AudioOps = require("@rosetta/ops/AudioOps") local AudioOps = require("@rosetta/ops/AudioOps")
local Types = require("@rosetta/Types") local Types = require("@rosetta/Types")
@@ -31,7 +29,6 @@ local sine = audio(8000, 2, 8000, function(f, c)
return (if c == 0 then 0.5 else 0.25) * math.sin(2 * math.pi * 440 * f / 8000) return (if c == 0 then 0.5 else 0.25) * math.sin(2 * math.pi * 440 * f / 8000)
end) end)
-- toAudio
do do
local dec = Pcm.audioDecoder(sine) local dec = Pcm.audioDecoder(sine)
local a = AudioOps.toAudio(dec) :: Types.Audio local a = AudioOps.toAudio(dec) :: Types.Audio
@@ -41,7 +38,6 @@ do
t:check(e2 and e2.code == Err.LIMIT, "maxFrames -> LIMIT") t:check(e2 and e2.code == Err.LIMIT, "maxFrames -> LIMIT")
end end
-- levels
do do
local p, per = AudioOps.peak(sine) local p, per = AudioOps.peak(sine)
t:check(near(p :: number, 0.5, 1e-3) and near((per :: any)[2], 0.25, 1e-3), "peak") t:check(near(p :: number, 0.5, 1e-3) and near((per :: any)[2], 0.25, 1e-3), "peak")
@@ -57,7 +53,6 @@ do
t:check(z and z.frames == 10, "normalize silence") t:check(z and z.frames == 10, "normalize silence")
end end
-- channels
do do
-- 5.1 (WAVE order FL FR C LFE BL BR) with distinct constants -- 5.1 (WAVE order FL FR C LFE BL BR) with distinct constants
local five = audio(8000, 6, 4, function(_, c) local five = audio(8000, 6, 4, function(_, c)
@@ -81,7 +76,6 @@ do
t:check(e and e.code == Err.ARG, "downmix to more channels: ARG") t:check(e and e.code == Err.ARG, "downmix to more channels: ARG")
end end
-- time
do do
local r = AudioOps.resample(sine, 16000) :: Types.Audio local r = AudioOps.resample(sine, 16000) :: Types.Audio
t:check(r.sampleRate == 16000 and r.frames == 16000, "resample 8 -> 16 kHz") t:check(r.sampleRate == 16000 and r.frames == 16000, "resample 8 -> 16 kHz")
@@ -108,7 +102,6 @@ do
t:check(at(fd, 0, 0) == 0 and near(at(fd, 2000, 0), at(sine, 2000, 0) * 0.5, 1e-6) and near(at(fd, 7999, 0), 0), "fades") t:check(at(fd, 0, 0) == 0 and near(at(fd, 2000, 0), at(sine, 2000, 0) * 0.5, 1e-6) and near(at(fd, 7999, 0), 0), "fades")
end end
-- bad arguments: Err.ARG, never a throw
do do
local junk: { any } = { nil, 5, "x", {}, { kind = "audio" }, Types.Image.new(2, 2) } local junk: { any } = { nil, 5, "x", {}, { kind = "audio" }, Types.Image.new(2, 2) }
local calls = { local calls = {
@@ -134,7 +127,6 @@ do
t:check(AudioOps.remix(sine, 0) == nil, "zero channels") t:check(AudioOps.remix(sine, 0) == nil, "zero channels")
end end
-- the F.ops facade
do do
t:check(F.ops.audio == AudioOps, "F.ops.audio") t:check(F.ops.audio == AudioOps, "F.ops.audio")
t:check(F.ops.image ~= nil and type(F.ops.image.resize) == "function", "F.ops.image") t:check(F.ops.image ~= nil and type(F.ops.image.resize) == "function", "F.ops.image")
@@ -147,5 +139,4 @@ do
t:check(F.ops.nothing == nil, "unknown ops: nil") t:check(F.ops.nothing == nil, "unknown ops: nil")
end end
-- (no decoder here: the no-throw pass is the bad-arguments block above)
t:done() t:done()
+1 -15
View File
@@ -1,8 +1,4 @@
-- ops/ImageOps tests: against Pillow (tools/fixtures/imageops.py): grey conversion (exact), resize nearest / bilinear / -- ops/ImageOps tests against Pillow (tools/fixtures/imageops.py) and property tests.
-- Lanczos up and down (max error), rotate with bilinear + expand (PSNR), alpha_composite (exact); property tests for
-- every pixel format (conversion round trips, flips, quarter turns, crop, premultiply, pixel access, fill), blit
-- clipping and blend modes, animation helpers (coalesce with each disposal, fromFrames, durations), and a pass of bad
-- arguments that must return nil, Err without throwing.
local T = require("@tests/T") local T = require("@tests/T")
local Ops = require("@rosetta/ops/ImageOps") local Ops = require("@rosetta/ops/ImageOps")
local Types = require("@rosetta/Types") local Types = require("@rosetta/Types")
@@ -17,7 +13,6 @@ local function image(w: number, h: number, fmt: string, px: string): any
return img return img
end end
-- max abs difference and PSNR of two byte strings / buffers
local function diff(a: buffer, b: string): (number, number) local function diff(a: buffer, b: string): (number, number)
local n = #b local n = #b
local mx, se = 0, 0 local mx, se = 0, 0
@@ -36,7 +31,6 @@ local rgb = image(Fx.rgb.w, Fx.rgb.h, "rgb8", Fx.rgb.px)
local rgba = image(Fx.rgba.w, Fx.rgba.h, "rgba8", Fx.rgba.px) local rgba = image(Fx.rgba.w, Fx.rgba.h, "rgba8", Fx.rgba.px)
local rgba2 = image(Fx.rgba2.w, Fx.rgba2.h, "rgba8", Fx.rgba2.px) local rgba2 = image(Fx.rgba2.w, Fx.rgba2.h, "rgba8", Fx.rgba2.px)
-- Pillow references
do do
local g = Ops.convert(rgb, "gray8") :: any local g = Ops.convert(rgb, "gray8") :: any
t:check(buffer.tostring(g.pixels) == Fx.gray, "rgb8 -> gray8 matches Pillow convert('L')") t:check(buffer.tostring(g.pixels) == Fx.gray, "rgb8 -> gray8 matches Pillow convert('L')")
@@ -67,7 +61,6 @@ do
t:check(mx == 0, "alpha_composite matches Pillow exactly (max error " .. mx .. ")") t:check(mx == 0, "alpha_composite matches Pillow exactly (max error " .. mx .. ")")
end end
-- conversions between every format
local FORMATS = { "rgba8", "rgba16", "rgbaf32", "rgb8", "gray8", "gray16", "graya8", "alpha8", "yuv420p" } local FORMATS = { "rgba8", "rgba16", "rgbaf32", "rgb8", "gray8", "gray16", "graya8", "alpha8", "yuv420p" }
do do
for _, f in FORMATS do for _, f in FORMATS do
@@ -104,7 +97,6 @@ do
t:check(buffer.readu8(b.pixels, 0) == 255 and buffer.readu8(b.pixels, 1) == 0 and buffer.readu8(b.pixels, 2) == 128, "float -> 8 bit clamps and rounds") t:check(buffer.readu8(b.pixels, 0) == 255 and buffer.readu8(b.pixels, 1) == 0 and buffer.readu8(b.pixels, 2) == 128, "float -> 8 bit clamps and rounds")
end end
-- geometry properties on every format
do do
for _, f in FORMATS do for _, f in FORMATS do
local img = Ops.convert(rgba, f) :: any local img = Ops.convert(rgba, f) :: any
@@ -131,7 +123,6 @@ do
local rr = Ops.rotate(img, 33) :: any local rr = Ops.rotate(img, 33) :: any
t:check(rr and rr.format == f, f .. ": rotate 33") t:check(rr and rr.format == f, f .. ": rotate 33")
end end
-- crop content, nearest identity, ccw convention
local c = Ops.crop(rgba, 3, 4, 5, 6) :: any local c = Ops.crop(rgba, 3, 4, 5, 6) :: any
t:check(buffer.readu32(c.pixels, 0) == buffer.readu32(rgba.pixels, (4 * rgba.width + 3) * 4), "crop origin") t:check(buffer.readu32(c.pixels, 0) == buffer.readu32(rgba.pixels, (4 * rgba.width + 3) * 4), "crop origin")
t:check(buffer.tostring((Ops.resize(rgba, rgba.width, rgba.height, "lanczos") :: any).pixels) == buffer.tostring(rgba.pixels), "same-size resize is a copy") t:check(buffer.tostring((Ops.resize(rgba, rgba.width, rgba.height, "lanczos") :: any).pixels) == buffer.tostring(rgba.pixels), "same-size resize is a copy")
@@ -139,7 +130,6 @@ do
t:eq(buffer.readu32(q.pixels, 0), buffer.readu32(rgba.pixels, (rgba.width - 1) * 4), "rotate90 is counter-clockwise") t:eq(buffer.readu32(q.pixels, 0), buffer.readu32(rgba.pixels, (rgba.width - 1) * 4), "rotate90 is counter-clockwise")
end end
-- pixels, fill, premultiply
do do
for _, f in FORMATS do for _, f in FORMATS do
local img = Ops.new(3, 2, f) :: any local img = Ops.new(3, 2, f) :: any
@@ -173,7 +163,6 @@ do
t:note("premultiply round trip: max error %d for alpha >= 32", worst) t:note("premultiply round trip: max error %d for alpha >= 32", worst)
end end
-- blit
do do
local dst = Ops.new(10, 10, "rgba8") :: any local dst = Ops.new(10, 10, "rgba8") :: any
Ops.fill(dst, 10, 20, 30, 255) Ops.fill(dst, 10, 20, 30, 255)
@@ -191,7 +180,6 @@ do
Ops.blit(dst, src, 5, 5, { opacity = 0.5 }) Ops.blit(dst, src, 5, 5, { opacity = 0.5 })
local r = Ops.getPixel(dst, 5, 5) local r = Ops.getPixel(dst, 5, 5)
t:check(math.abs(r - 133) <= 1, "opacity 0.5 over (10 -> " .. r .. ")") t:check(math.abs(r - 133) <= 1, "opacity 0.5 over (10 -> " .. r .. ")")
-- rgb8 destination, gray source, float destination
local d3 = Ops.convert(dst, "rgb8") :: any local d3 = Ops.convert(dst, "rgb8") :: any
t:check(Ops.blit(d3, Ops.convert(src, "graya8") :: any, 1, 1) == d3, "blit onto rgb8") t:check(Ops.blit(d3, Ops.convert(src, "graya8") :: any, 1, 1) == d3, "blit onto rgb8")
local df = Ops.convert(dst, "rgbaf32") :: any local df = Ops.convert(dst, "rgbaf32") :: any
@@ -200,7 +188,6 @@ do
t:check(Ops.blit(dy, src, 3, 3) == dy, "blit onto yuv420p") t:check(Ops.blit(dy, src, 3, 3) == dy, "blit onto yuv420p")
end end
-- animation helpers
do do
local W, H = 6, 4 local W, H = 6, 4
local function solid(w: number, h: number, r: number, a: number): any local function solid(w: number, h: number, r: number, a: number): any
@@ -241,7 +228,6 @@ do
t:check(Ops.fromFrames({ fr[1], rgba }) == nil, "fromFrames refuses mixed sizes") t:check(Ops.fromFrames({ fr[1], rgba }) == nil, "fromFrames refuses mixed sizes")
end end
-- bad arguments: nil, Err, never a throw
do do
local rand = T.rng(5) local rand = T.rng(5)
local junk: { any } = { nil, 0, -1, 1.5, 2 ^ 40, "x", {}, true, 0 / 0, math.huge, -7 } local junk: { any } = { nil, 0, -1, 1.5, 2 ^ 40, "x", {}, true, 0 / 0, math.huge, -7 }
+1 -5
View File
@@ -1,6 +1,4 @@
-- ops/LayerOps + codecs/image/Blend tests: blend mode formulas on single pixels against hand-computed W3C values, opacity, -- ops/LayerOps + codecs/image/Blend tests against hand-computed W3C values (flattening: tests/layered/psd.luau).
-- masks, clipping, isolated vs pass-through groups, hidden layers, frames, leaves, bad arguments. (Whole-document
-- flattening against psd-tools is in tests/layered/psd.luau.)
local T = require("@tests/T") local T = require("@tests/T")
local LayerOps = require("@rosetta/ops/LayerOps") local LayerOps = require("@rosetta/ops/LayerOps")
local Blend = require("@rosetta/codecs/image/Blend") local Blend = require("@rosetta/codecs/image/Blend")
@@ -72,7 +70,6 @@ do
local r2, _, _, a2 = get(LayerOps.flatten(doc({ top }))) local r2, _, _, a2 = get(LayerOps.flatten(doc({ top })))
t:check(r2 == 255 and math.abs(a2 - 128) <= 1, "over transparent: alpha scales") t:check(r2 == 255 and math.abs(a2 - 128) <= 1, "over transparent: alpha scales")
end end
-- hidden layers, masks, clipping
do do
local top = L("top", px(255, 0, 0, 255)) local top = L("top", px(255, 0, 0, 255))
top.visible = false top.visible = false
@@ -124,7 +121,6 @@ do
t:check(math.abs(get(LayerOps.flatten(doc({ bottom, g }))) - 100) <= 1, "pass-through: disabled mask ignored") t:check(math.abs(get(LayerOps.flatten(doc({ bottom, g }))) - 100) <= 1, "pass-through: disabled mask ignored")
g.mask = nil g.mask = nil
end end
-- frames, leaves, flattenFrames
do do
local d = doc({ L("a", px(1, 2, 3, 255)) }) local d = doc({ L("a", px(1, 2, 3, 255)) })
d.frames = { { layers = d.layers, delay = 0.1 }, { layers = { L("b", px(9, 8, 7, 255)) }, delay = 0.2 } } d.frames = { { layers = d.layers, delay = 0.1 }, { layers = { L("b", px(9, 8, 7, 255)) }, delay = 0.2 } }
+2 -15
View File
@@ -1,8 +1,4 @@
-- ops/MeshOps tests: triangulate (strips, fans, convex / concave / degenerate n-gons), transform (normals by the inverse -- ops/MeshOps tests against analytic references (closed forms).
-- transpose, mirrors flip the winding), computeNormals (smooth sphere normals = the radial direction, flat cube normals),
-- computeTangents (orthogonal, unit, handedness), weld / unweld, bounds, merge (instances baked, mixed attributes),
-- scale / setUnit / setUp, greedy voxel meshing (exposed face area, winding, the checkerboard worst case), errors.
-- Analytic references (closed forms); the format tests check merge / bounds against assimp and trimesh.
local T = require("@tests/T") local T = require("@tests/T")
local MeshOps = require("@rosetta/ops/MeshOps") local MeshOps = require("@rosetta/ops/MeshOps")
local Types = require("@rosetta/Types") local Types = require("@rosetta/Types")
@@ -52,7 +48,6 @@ local function area(prim: any): number
return total return total
end end
-- a unit cube as 6 quads (polygons), 24 corners
local function cube(): Types.Primitive local function cube(): Types.Primitive
local P = {} local P = {}
local faces = { local faces = {
@@ -76,7 +71,6 @@ local function cube(): Types.Primitive
return { attributes = { POSITION = f32(P, 3) }, indices = u32(ind), faces = u32(sizes), mode = "polygons" } return { attributes = { POSITION = f32(P, 3) }, indices = u32(ind), faces = u32(sizes), mode = "polygons" }
end end
-- triangulate
do do
local c = cube() local c = cube()
local tri = MeshOps.triangulate(c) :: any local tri = MeshOps.triangulate(c) :: any
@@ -95,7 +89,6 @@ do
end end
end end
t:check(outward, "triangulated winding keeps the faces outward") t:check(outward, "triangulated winding keeps the faces outward")
-- strips and fans
local P = f32({ 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 2, 0, 1, 2, 0 }, 3) local P = f32({ 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 2, 0, 1, 2, 0 }, 3)
local strip = MeshOps.triangulate({ attributes = { POSITION = P }, mode = "triangle_strip" }) :: any local strip = MeshOps.triangulate({ attributes = { POSITION = P }, mode = "triangle_strip" }) :: any
t:check(table.concat(idx(strip.indices), ",") == "0,1,2,2,1,3,2,3,4,4,3,5", "strip unrolled with alternating winding") t:check(table.concat(idx(strip.indices), ",") == "0,1,2,2,1,3,2,3,4,4,3,5", "strip unrolled with alternating winding")
@@ -130,7 +123,6 @@ do
t:check(MeshOps.triangulate(lines) == lines, "lines come back unchanged") t:check(MeshOps.triangulate(lines) == lines, "lines come back unchanged")
end end
-- transform
do do
local tri = MeshOps.triangulate(cube()) :: any local tri = MeshOps.triangulate(cube()) :: any
MeshOps.computeNormals(MeshOps.unweld(tri)) MeshOps.computeNormals(MeshOps.unweld(tri))
@@ -173,7 +165,6 @@ do
t:check(e and e.code == Err.ARG, "transform: a bad matrix") t:check(e and e.code == Err.ARG, "transform: a bad matrix")
end end
-- normals, tangents on a UV sphere
do do
local rings, segs = 16, 32 local rings, segs = 16, 32
local P, UV, ind = {}, {}, {} local P, UV, ind = {}, {}, {}
@@ -253,7 +244,6 @@ do
t:check(axis, "flat cube normals are axis-aligned") t:check(axis, "flat cube normals are axis-aligned")
end end
-- weld
do do
local soup = MeshOps.unweld(MeshOps.triangulate(cube()) :: any) :: any local soup = MeshOps.unweld(MeshOps.triangulate(cube()) :: any) :: any
t:eq(soup.attributes.POSITION.count, 36, "unwelded cube: 36 vertices") t:eq(soup.attributes.POSITION.count, 36, "unwelded cube: 36 vertices")
@@ -271,7 +261,6 @@ do
t:eq(positionsOnly.attributes.POSITION.count, 8, "positionsOnly: 8") t:eq(positionsOnly.attributes.POSITION.count, 8, "positionsOnly: 8")
end end
-- merge, bounds
do do
local s = S.new() local s = S.new()
local tri = MeshOps.triangulate(cube()) :: any local tri = MeshOps.triangulate(cube()) :: any
@@ -301,11 +290,10 @@ do
t:check(e and e.code == Err.ARG, "merge junk") t:check(e and e.code == Err.ARG, "merge junk")
end end
-- units and up axis
do do
local s = S.fromPrimitive(MeshOps.triangulate(cube()) :: any) local s = S.fromPrimitive(MeshOps.triangulate(cube()) :: any)
s.nodes[1].translation = { 1, 2, 3 } s.nodes[1].translation = { 1, 2, 3 }
s.meta.unit = 0.01 -- centimetres s.meta.unit = 0.01
MeshOps.setUnit(s, 1) MeshOps.setUnit(s, 1)
local lo, hi = MeshOps.bounds(s) local lo, hi = MeshOps.bounds(s)
t:check(lo and near(lo[1], 0.01) and near(hi[1], 0.02) and near(lo[3], 0.03), "cm -> m") t:check(lo and near(lo[1], 0.01) and near(hi[1], 0.02) and near(lo[3], 0.03), "cm -> m")
@@ -318,7 +306,6 @@ do
t:check(MeshOps.setUp(s, "x" :: any) == nil, "setUp: bad axis") t:check(MeshOps.setUp(s, "x" :: any) == nil, "setUp: bad axis")
end end
-- greedy voxels
do do
local v = Types.Voxels.new(4, 4, 4) local v = Types.Voxels.new(4, 4, 4)
for x = 0, 3 do for x = 0, 3 do
+2 -13
View File
@@ -1,6 +1,4 @@
-- ops/MusicOps tests (F.music.new / addPattern / setCell / getCell / addSample / addInstrument / note) and the -- ops/MusicOps tests and the music-as-audio bridges of the api; everything is built here (no fixtures).
-- music-as-audio bridges of the api: F.save / F.convert of a Module or a Midi to an audio format (rendered, render
-- options through opts), F.audio.open / F.audio.load of music bytes. Everything is built here (no fixtures).
local T = require("@tests/T") local T = require("@tests/T")
local F = require("@rosetta") local F = require("@rosetta")
local Err = require("@rosetta/core/Err") local Err = require("@rosetta/core/Err")
@@ -16,7 +14,6 @@ local function sine(rate: number, frames: number): any
return a return a
end end
-- note names
do do
t:eq(F.music.note("C-0"), 1, "C-0") t:eq(F.music.note("C-0"), 1, "C-0")
t:eq(F.music.note("C-4"), 49, "C-4") t:eq(F.music.note("C-4"), 49, "C-4")
@@ -32,7 +29,6 @@ do
end end
end end
-- a MOD built from scratch: saved, reloaded, rendered
local a = sine(8363, 8363) local a = sine(8363, 8363)
local song = assert(F.music.new({ format = "mod", channels = 4, title = "demo", speed = 3 })) local song = assert(F.music.new({ format = "mod", channels = 4, title = "demo", speed = 3 }))
do do
@@ -47,7 +43,6 @@ do
t:check(F.music.setCell(song, p, 32, 2, { note = "E-4", instrument = s, effect = 0xC, param = 32 }), "setCell 2") t:check(F.music.setCell(song, p, 32, 2, { note = "E-4", instrument = s, effect = 0xC, param = 32 }), "setCell 2")
local c = assert(F.music.getCell(song, p, 32, 2)) local c = assert(F.music.getCell(song, p, 32, 2))
t:check(c.note == 53 and c.instrument == 1 and c.effect == 0xC and c.param == 32 and c.volume == 0, "getCell") t:check(c.note == 53 and c.instrument == 1 and c.effect == 0xC and c.param == 32 and c.volume == 0, "getCell")
-- bad arguments
local _, e1 = F.music.setCell(song, p, 64, 1, {}) local _, e1 = F.music.setCell(song, p, 64, 1, {})
t:check(e1 and e1.code == Err.ARG, "row out of range") t:check(e1 and e1.code == Err.ARG, "row out of range")
local _, e2 = F.music.setCell(song, p, 0, 5, {}) local _, e2 = F.music.setCell(song, p, 0, 5, {})
@@ -65,7 +60,7 @@ do
local _, e8 = F.music.addPattern({} :: any) local _, e8 = F.music.addPattern({} :: any)
t:check(e8 and e8.code == Err.ARG, "not a module") t:check(e8 and e8.code == Err.ARG, "not a module")
local mod = assert(F.save(song)) -- the source format local mod = assert(F.save(song))
t:eq(F.detect(mod), "mod", "saved as MOD") t:eq(F.detect(mod), "mod", "saved as MOD")
local back = assert(F.music.load(mod)) local back = assert(F.music.load(mod))
t:eq(back.title, "demo", "title round trip") t:eq(back.title, "demo", "title round trip")
@@ -77,7 +72,6 @@ do
t:check(au.frames > 22050 and F.ops.audio.peak(au) > 0.05, "renders sound") t:check(au.frames > 22050 and F.ops.audio.peak(au) > 0.05, "renders sound")
end end
-- an XM with an instrument and a volume envelope
do do
local xm = assert(F.music.new({ format = "xm", channels = 2 })) local xm = assert(F.music.new({ format = "xm", channels = 2 }))
local s = assert(F.music.addSample(xm, { audio = a, rate = 16726 })) -- an octave up: relativeNote 12 local s = assert(F.music.addSample(xm, { audio = a, rate = 16726 })) -- an octave up: relativeNote 12
@@ -96,7 +90,6 @@ do
t:check(eenv and eenv.code == Err.ARG, "envelope ticks must increase") t:check(eenv and eenv.code == Err.ARG, "envelope ticks must increase")
end end
-- music saved and converted as audio: rendered, with the render options from opts
do do
local wav = assert(F.save(song, nil, { format = "wav", sampleRate = 22050 })) local wav = assert(F.save(song, nil, { format = "wav", sampleRate = 22050 }))
local au = assert(F.audio.load(wav)) local au = assert(F.audio.load(wav))
@@ -118,7 +111,6 @@ do
local mid = assert(F.save(m, nil, { format = "midi" })) local mid = assert(F.save(m, nil, { format = "midi" }))
t:eq(F.detect(assert(F.convert(mid, "wav"))), "wav", "F.convert(midi, wav)") t:eq(F.detect(assert(F.convert(mid, "wav"))), "wav", "F.convert(midi, wav)")
-- F.audio.open / load of music bytes: the rendered Decoder
local d1 = assert(F.audio.open(mid, { tail = 0 })) local d1 = assert(F.audio.open(mid, { tail = 0 }))
t:check(d1.channels == 2 and d1.sampleRate == 44100 and d1.frames == 22050, "F.audio.open(midi)") t:check(d1.channels == 2 and d1.sampleRate == 44100 and d1.frames == 22050, "F.audio.open(midi)")
local d2 = assert(F.audio.open(mod)) local d2 = assert(F.audio.open(mod))
@@ -127,15 +119,12 @@ do
t:check(a2.kind == "audio" and a2.sampleRate == 8000, "F.audio.load(mod)") t:check(a2.kind == "audio" and a2.sampleRate == 8000, "F.audio.load(mod)")
local d3 = assert(F.audio.open(mod, { format = "mod" })) local d3 = assert(F.audio.open(mod, { format = "mod" }))
t:check(d3.frames > 0, "F.audio.open with format = mod") t:check(d3.frames > 0, "F.audio.open with format = mod")
-- still an error for data no format reads
local _, e = F.audio.open(buffer.fromstring("not audio at all")) local _, e = F.audio.open(buffer.fromstring("not audio at all"))
t:check(e and e.code == Err.UNKNOWN_FORMAT, "unknown data") t:check(e and e.code == Err.UNKNOWN_FORMAT, "unknown data")
-- and a soundfont is not audio
local _, e2 = F.audio.save(m, nil, { format = "png" }) local _, e2 = F.audio.save(m, nil, { format = "png" })
t:check(e2 ~= nil, "music to a non-audio format fails") t:check(e2 ~= nil, "music to a non-audio format fails")
end end
-- no throws on random cell / sample arguments
do do
local rng = T.rng(7) local rng = T.rng(7)
local ok = true local ok = true