Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"!rs/moq-mux/src/container/ts/test_data",
"!rs/moq-audio/src/decode/test_data/*.ts",
"!**/*.svg",
"!doc/concept/audio-jitter/*.json",
"!doc/concept/audio-jitter/**/*.json",
"!test/audio-quality/traces/*.json",
"!nix/crate-hashes.json"
]
Expand Down Expand Up @@ -125,9 +125,11 @@
{
"group": [
"**/concept/audio-jitter/reference",
"**/concept/audio-jitter/reference.*"
"**/concept/audio-jitter/reference.*",
"**/concept/audio-jitter/stretch/reference",
"**/concept/audio-jitter/stretch/reference.*"
],
"message": "doc/concept/audio-jitter/reference.ts is non-normative. Implement the document, don't import the reference."
"message": "The references under doc/concept/audio-jitter are non-normative. Implement the document, don't import a reference."
}
]
}
Expand Down
389 changes: 177 additions & 212 deletions doc/concept/audio-jitter.md

Large diffs are not rendered by default.

2,510 changes: 1 addition & 2,509 deletions doc/concept/audio-jitter/stretch/corpus.json

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions doc/concept/audio-jitter/stretch/corpus.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// The corpus is data the two players are graded against, so the one thing this has to catch is
// the corpus drifting from the algorithm it claims to encode: a checked-in file edited by hand to
// make a failing implementation pass would otherwise go unnoticed.
//
// Grading an implementation is each language's own test suite: js/watch's stretch.test.ts and
// moq-audio's stretch.rs.

import { describe, expect, test } from "bun:test";
import { readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { type Case, cases, type Rule, rules } from "./corpus";

const here = dirname(fileURLToPath(import.meta.url));
function read<T>(name: string): T {
return JSON.parse(readFileSync(join(here, name), "utf8")) as T;
}

describe("audio stretch corpus", () => {
test("the decisions match the checked-in file", () => {
expect(read<Rule[]>("decisions.json")).toEqual(rules);
});

const actual = read<Case[]>("corpus.json");
test("the cases match the checked-in file", () => {
expect(actual.map(({ name }) => name)).toEqual(cases.map(({ name }) => name));
});

for (const expected of cases) {
describe(expected.name, () => {
const found = actual.find(({ name }) => name === expected.name);

test("matches the checked-in case", () => {
expect(found).toEqual(expected);
});

test("decides every hop it plays", () => {
expect(expected.decisions.length).toBeGreaterThan(0);
expect(expected.shifts.length).toBeGreaterThanOrEqual(expected.decisions.length);
});

test("moves the output by exactly the shifts it took", () => {
const frames = expected.input.length / expected.channels;
const moved = expected.shifts.reduce((sum, shift) => sum + shift, 0);
expect(expected.output.length / expected.channels).toBe(frames - moved);
});
});
}
});
Loading