feat: dataset builder
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
a1e9ce86a0
commit
ca9f3bbb83
@@ -0,0 +1,37 @@
|
||||
import { test, expect } from "bun:test";
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { buildSong, loadSongDir } from "../../src/bench/dataset.ts";
|
||||
|
||||
test("buildSong writes all artefacts; loadSongDir reads them; stems sum to mix; idempotent", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "stsheets-ds-"));
|
||||
try {
|
||||
const dir = await buildSong("t1a", 1, root);
|
||||
const files = ["song.json", "truth.gp", "mix.wav", "mix.mp3"];
|
||||
for (const f of files) expect(await Bun.file(join(dir, f)).exists()).toBe(true);
|
||||
const { song, truth, mix, stems } = await loadSongDir(dir);
|
||||
for (const t of song.tracks) expect(await Bun.file(join(dir, "stems", `${t.name}.wav`)).exists()).toBe(true);
|
||||
expect(truth.tracks[0]!.notes.length).toBe(song.tracks[0]!.notes.length);
|
||||
expect(mix.channels.length).toBe(2);
|
||||
|
||||
// Oracle stems are the exact mix contributions: they sum to the mix (PCM16 rounding only).
|
||||
expect(stems.size).toBe(song.tracks.length);
|
||||
let maxDiff = 0;
|
||||
for (let c = 0; c < mix.channels.length; c++) {
|
||||
const m = mix.channels[c]!;
|
||||
for (let i = 0; i < m.length; i++) {
|
||||
let s = 0;
|
||||
for (const a of stems.values()) s += a.channels[c]![i] ?? 0;
|
||||
maxDiff = Math.max(maxDiff, Math.abs(s - m[i]!));
|
||||
}
|
||||
}
|
||||
expect(maxDiff).toBeLessThan(2e-3);
|
||||
|
||||
const before = (await Bun.file(join(dir, "mix.mp3")).stat()).mtimeMs;
|
||||
expect(await buildSong("t1a", 1, root)).toBe(dir);
|
||||
expect((await Bun.file(join(dir, "mix.mp3")).stat()).mtimeMs).toBe(before);
|
||||
} finally {
|
||||
await rm(root, { recursive: true, force: true });
|
||||
}
|
||||
}, 120_000);
|
||||
Reference in New Issue
Block a user