AquaSynth/tools/aqua-feel/feel.mjs
Aqua 1bf99e5c3f aqua-feel: review fixes (attack on low tones, disarmed guards, bounded waivers, drift test)
- attack: peak-hold envelope and a 150 ms window; a 261 Hz tone no longer reads its
  first half-cycle as the attack (warm-bell 0.67 ms -> 3.8 ms, declared 4 ms).
- gate: a rule whose id matches no item fails a full run; waivers carry a bound and
  cover only up to it; a missing metric fails its rule; silent items fail once;
  --only runs gate as partial; silent threshold is -70 dBFS.
- DingCatalogTests: lowered Dings fed to the meter must match the catalog.
- README states NTR window/Q dependence, short-buffer loudness padding and the assumed
  Ding command gain; faust-toolchain-boundary notes the v5 manifest predates the mix change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-05 15:42:13 +00:00

66 lines
4.2 KiB
JavaScript

#!/usr/bin/env node
// aqua-feel: headless feel meter. Renders every shipped patch and Ding offline, measures the buffers, writes
// report.json plus a static gallery, and gates the numbers against thresholds.json.
// NOTHING HERE HEARS ANYTHING. These are measurements of rendered buffers; a number is evidence, never a verdict.
// Usage: node feel.mjs run [--out DIR] [--only SUBSTR] [--no-gate] render, measure, write report + gallery, gate
// node feel.mjs gate REPORT.json [THRESHOLDS.json] [--partial] re-gate a report (--partial: a subset; skips id-rule and waiver bookkeeping)
// node feel.mjs compare BEFORE.json AFTER.json [--only SUBSTR] before/after table
// node feel.mjs correlate TRIAL_EXPORT.json ... feel metrics vs listening-trial ratings
import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { measure, SR } from "./metrics.js";
import { loadRuntime, compile, renderOnce, renderDing, writeWav } from "./render.js";
import { allItems } from "./catalog.js";
import { gate, formatGate } from "./gate.js";
import { gallery } from "./gallery.js";
import { compareTable, correlate } from "./report.js";
const here = dirname(fileURLToPath(import.meta.url));
export const CAVEAT = "Nothing here was heard. These are measurements of offline-rendered buffers (faustwasm, mono channel 0); metrics are evidence for a listener to check, not verdicts.";
const args = process.argv.slice(2), cmd = args.shift();
const flag = (n) => { const i = args.indexOf(n); if (i < 0) return undefined; return args.splice(i, i + 2 > args.length ? 1 : 2).pop(); };
const bool = (n) => { const i = args.indexOf(n); if (i < 0) return false; args.splice(i, 1); return true; };
const readJson = (p) => JSON.parse(readFileSync(p, "utf8"));
async function run() {
const out = resolve(flag("--out") ?? join(here, "out")), only = flag("--only"), noGate = bool("--no-gate");
const items = allItems().filter((it) => !only || it.id.includes(only));
if (!items.length) { console.error(`no item matches ${only}`); process.exit(2); }
const rt = await loadRuntime();
console.log(`libfaust ${rt.version}; ${items.length} items; ${SR} Hz`);
const records = [];
for (const it of items) {
const t0 = Date.now();
try {
const r = it.ding ? await renderDing(rt, it.ding.instrument, it.ding.source, it.ding.event, it.ding) : await renderOnce(await compile(rt, it.id, it.source), it.params, it.seconds);
const wav = `wav/${it.id.replace(/[^A-Za-z0-9._@-]+/g, "_")}.wav`;
writeWav(join(out, wav), r.samples);
records.push({ id: it.id, group: it.group, origin: it.origin, params: it.params ?? {}, seconds: r.samples.length / SR, channels: r.channels, wav, metrics: measure(r.samples) });
console.log(`ok ${it.id} (${Date.now() - t0} ms)`);
} catch (e) {
records.push({ id: it.id, group: it.group, origin: it.origin, error: String(e.message ?? e) });
console.log(`FAIL ${it.id}: ${e.message}`);
}
}
const thresholds = readJson(join(here, "thresholds.json"));
const report = { schema: "aqua-feel.report.v1", caveat: CAVEAT, libfaust: rt.version, sampleRate: SR, items: records };
report.gate = gate(report, thresholds, { partial: Boolean(only) });
mkdirSync(out, { recursive: true });
writeFileSync(join(out, "report.json"), JSON.stringify(report, null, 1));
writeFileSync(join(out, "index.html"), gallery(report));
console.log(`\nwrote ${join(out, "report.json")} and index.html\n${CAVEAT}\n\n${formatGate(report.gate)}`);
process.exit(!noGate && !report.gate.pass ? 1 : 0);
}
const cmds = {
run,
gate() {
const partial = bool("--partial"), report = readJson(args[0]), g = gate(report, readJson(args[1] ?? join(here, "thresholds.json")), { partial });
console.log(formatGate(g)); process.exit(g.pass ? 0 : 1);
},
compare() { const only = flag("--only"); console.log(compareTable(readJson(args[0]), readJson(args[1]), only)); },
async correlate() { console.log(await correlate(args.map(readJson), join(here, "../aqua-trial"))); },
};
if (!cmds[cmd]) { console.error(readFileSync(fileURLToPath(import.meta.url), "utf8").split("\n").slice(1, 9).join("\n")); process.exit(2); }
await cmds[cmd]();