fix: dataset layout data/<tier>/<seed>, mix tests, cli hardening

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
Lucas Winther
2026-10-30 02:52:50 +01:00
co-authored by Claude Sonnet 5.5
parent ca9f3bbb83
commit 32d96cadcc
4 changed files with 53 additions and 5 deletions
+5 -2
View File
@@ -15,7 +15,10 @@ function parseSeeds(s: string): number[] {
function arg(args: string[], name: string, def: string): string {
const i = args.indexOf(`--${name}`);
return i >= 0 && args[i + 1] ? args[i + 1]! : def;
if (i < 0) return def;
const v = args[i + 1];
if (v === undefined || v.startsWith("--")) throw new Error(`missing value for --${name}`);
return v;
}
async function main() {
@@ -23,7 +26,7 @@ async function main() {
switch (cmd) {
case "gen": {
const tiers = arg(rest, "tiers", "t1a,t1b,t1c,t1d").split(",") as TierId[];
for (const t of tiers) if (!(t in TIERS)) throw new Error(`unknown tier: ${t}`);
for (const t of tiers) if (!Object.hasOwn(TIERS, t)) throw new Error(`unknown tier: ${t}`);
const seeds = parseSeeds(arg(rest, "seeds", "1-5"));
const root = arg(rest, "root", "data");
for (const t of tiers) for (const s of seeds) {
+3 -3
View File
@@ -10,16 +10,16 @@ import { mixStemsScaled } from "../audio/mix.ts";
import { readWav, writeWav } from "../audio/wav.ts";
import { encodeMp3 } from "../audio/mp3.ts";
const SF2_PATH = "node_modules/@coderline/alphatab/dist/soundfont/sonivox.sf2";
const SF2_PATH = join(import.meta.dir, "../../node_modules/@coderline/alphatab/dist/soundfont/sonivox.sf2");
const SR = 44100;
/**
* Build one song into `<root>/<tier>-<seed>/`. Idempotent: skipped when mix.mp3 exists and song.json matches.
* Build one song into `<root>/<tier>/<seed>/`. Idempotent: skipped when mix.mp3 exists and song.json matches.
* stems/<track>.wav are exactly each track's contribution to mix.wav (post-fx, post-pan, gain, normalisation),
* so the stems sum to the mix up to PCM16 rounding.
*/
export async function buildSong(tier: TierId, seed: number, root = "data"): Promise<string> {
const dir = join(root, `${tier}-${seed}`);
const dir = join(root, tier, String(seed));
const song = generateSong(tier, seed);
const songJson = JSON.stringify(song, null, 1);
const jsonFile = Bun.file(join(dir, "song.json"));