tests/codecs (m-z): comments: specs only

This commit is contained in:
4DBug committed 2026-11-01 01:50:53 -05:00
1 parent 98b4ce533e
commit a6732d45f2
23 files changed
+46 -177

No files matched your search

+2 -9
View File
@@ -1,6 +1,4 @@
-- codecs/audio/Resample tests: sines through common rate pairs (44100 <-> 48000, 8000 -> 48000, 48000 -> 22050, an inexact
-- ratio) against the analytic signal, alias rejection when downsampling, output lengths, streaming in odd chunks =
-- the whole-buffer result, multichannel, a Pcm source wrapper, bad arguments, and a no-throw pass over garbage.
-- codecs/audio/Resample tests: sines against the analytic signal, alias rejection, streaming, a Pcm source.
local T = require("@tests/T")
local Resample = require("@rosetta/codecs/audio/Resample")
local Pcm = require("@rosetta/codecs/audio/Pcm")
@@ -19,7 +17,6 @@ local function sine(frames: number, ch: number, rate: number, freqs: { number })
return b
end
-- snr(out, frames, ch, rate, freqs, skip) -> dB of the analytic sine against the error, away from the edges
local function snr(b: buffer, frames: number, ch: number, rate: number, freqs: { number }, skip: number): number
local sig, err = 0, 0
for i = skip, frames - 1 - skip do
@@ -42,7 +39,6 @@ local function rms(b: buffer, frames: number, skip: number): number
return math.sqrt(s / math.max(1, frames - 2 * skip))
end
-- 1. accuracy on in-band sines
for _, c in { { 44100, 48000, 1000, "medium", 80 }, { 48000, 44100, 3000, "medium", 80 }, { 8000, 48000, 440, "medium", 80 }, { 48000, 22050, 5000, "high", 90 }, { 44100, 48000, 1000, "low", 55 }, { 44100, 47999, 1000, "medium", 75 } } do
local from, to, f, q, want = c[1], c[2], c[3], c[4], c[5]
local n = from // 4
@@ -65,7 +61,7 @@ do
t:check(level < 1e-3, string.format("alias rejection: %.2e", level))
end
-- 3. streaming in odd chunk sizes gives the whole-buffer result; stereo channels stay apart
-- streaming in odd chunk sizes gives the whole-buffer result; stereo channels stay apart
do
local n, ch = 10007, 2
local src = sine(n, ch, 44100, { 700, 1900 })
@@ -92,7 +88,6 @@ do
t:check(snr(got, gf, ch, 48000, { 700, 1900 }, 500) > 80, "stereo accuracy")
end
-- 4. a codecs/audio/Pcm source at a new rate
do
local a = Types.Audio.new(22050, 1, 5000)
a.samples = sine(5000, 1, 22050, { 500 })
@@ -103,7 +98,6 @@ do
t:check(col and snr(col.samples, col.frames, 1, 32000, { 500 }, 300) > 80, "source accuracy")
end
-- 5. identity, empty input, bad arguments
do
local src = sine(1000, 1, 48000, { 1000 })
local out = Resample.buffer(src, 1000, 1, 48000, 48000)
@@ -116,7 +110,6 @@ do
t:check(Resample.buffer(buffer.create(4), 10, 1, 44100, 48000) == nil, "short buffer")
end
-- 6. no throw on garbage (NaN / Inf samples, odd lengths, chunk sizes)
local samples = {}
for i = 1, 4 do
table.insert(samples, buffer.tostring(sine(100 * i, 1, 8000, { 300 })))