fix(cli): normalize-audio says where the target stays when a limit holds its gain (#7267)

* fix(cli): normalize-audio says where the target stays when a limit holds its gain

* fix(cli): normalize-audio held line counts the clip's data-volume in both modes

* style(cli): format the normalize-audio held-line change
This commit is contained in:
Miguel Ángel
2026-11-05 21:07:47 +00:00
committed by GitHub
parent 256b84a41b
commit 4935d6736b
2 changed files with 78 additions and 5 deletions
@@ -127,6 +127,35 @@ describe("normalize-audio on a clip inside a mounted scene", () => {
});
});
describe("absolute normalize-audio command held by a limit", () => {
it("prints the level the clip plays at, its data-volume included", async () => {
const dir = mkdtempSync(join(tmpdir(), "hf-normalize-absolute-held-test-"));
const log = vi.spyOn(console, "log").mockImplementation(() => {});
try {
const path = join(dir, "index.html");
const html = `<audio id="voice" src="voice.wav" data-volume="2" data-duration="2"></audio>`;
writeFileSync(path, html);
writeFileSync(join(dir, "voice.wav"), "audio bytes");
measureAudio.mockResolvedValue({ integratedLufs: -20, truePeakDbfs: -7.8 });
await runCommand(normalizeAudioCommand, {
rawArgs: [dir, "--target", "voice", "--lufs", "-12", "--write"],
});
const printed = log.mock.calls.map((call) => String(call[0])).join("\n");
expect(printed).toContain(
"-20.0 LUFS → -14.0 LUFS, target -12.0 (stopped short of -1.5 dBTP)",
);
expect(printed).toContain("Cannot get closer to the target; the gain is unchanged.");
expect(readFileSync(path, "utf8")).toBe(html);
} finally {
log.mockRestore();
measureAudio.mockReset();
rmSync(dir, { recursive: true, force: true });
}
});
});
describe("reference normalize-audio command", () => {
it("writes the most gain that stays under -1.5 dBTP and says how far under the reference that leaves it", async () => {
const dir = mkdtempSync(join(tmpdir(), "hf-normalize-reference-test-"));
@@ -160,4 +189,36 @@ describe("reference normalize-audio command", () => {
rmSync(dir, { recursive: true, force: true });
}
});
it("says where the target stays when the ceiling leaves less gain than the tolerance", async () => {
const dir = mkdtempSync(join(tmpdir(), "hf-normalize-reference-held-test-"));
const log = vi.spyOn(console, "log").mockImplementation(() => {});
try {
const path = join(dir, "index.html");
const html =
`<audio id="speaker-opening" src="open.wav" data-volume="1"></audio>` +
`<audio id="speaker-closing" src="close.wav" data-volume="1"></audio>`;
writeFileSync(path, html);
writeFileSync(join(dir, "open.wav"), "audio bytes");
writeFileSync(join(dir, "close.wav"), "audio bytes");
measureAudio
.mockResolvedValueOnce({ integratedLufs: -15, truePeakDbfs: -3 })
.mockResolvedValueOnce({ integratedLufs: -18, truePeakDbfs: -1.8 });
await runCommand(normalizeAudioCommand, {
rawArgs: [dir, "--reference", "speaker-opening", "--target", "speaker-closing", "--write"],
});
const printed = log.mock.calls.map((call) => String(call[0])).join("\n");
expect(printed).toContain(
"Stays at -18.0 LUFS, 3.0 dB under the reference (stopped short of -1.5 dBTP).",
);
expect(printed).toContain("Cannot get closer to the target; the gain is unchanged.");
expect(readFileSync(path, "utf8")).toBe(html);
} finally {
log.mockRestore();
measureAudio.mockReset();
rmSync(dir, { recursive: true, force: true });
}
});
});
+17 -5
View File
@@ -77,6 +77,8 @@ interface WriteOutcome {
ok: true;
wrote: boolean;
withinTolerance: boolean;
heldByLimit: boolean;
reachedLufs: number;
tolerance: number;
filePath: string;
}
@@ -198,7 +200,17 @@ async function normalizeAudio(options: NormalizeAudioOptions): Promise<Normalize
updateAudioVolume(readFileSync(filePath, "utf8"), targetTag.id, plan.volume),
);
}
return { ok: true, wrote, withinTolerance, tolerance, filePath, ...plan };
const reachedLufs = heldByLimit ? plan.projectedLufs - plan.changeDb : plan.projectedLufs;
return {
ok: true,
wrote,
withinTolerance,
heldByLimit,
reachedLufs,
tolerance,
filePath,
...plan,
};
}
function heldAtLimit(plan: ModePlan, tolerance: number): boolean {
@@ -218,9 +230,9 @@ function printMeasuredLine(result: NormalizeAudioResult): void {
`${c.bold(`#${result.targetId}`)} ${result.targetLufs.toFixed(1)} LUFS`,
);
if (result.limitedBy) {
const short = result.referenceLufs - result.projectedLufs;
console.log(
`Reaches ${result.projectedLufs.toFixed(1)} LUFS, ${short.toFixed(1)} dB under the reference ` +
`${result.heldByLimit ? "Stays at" : "Reaches"} ${result.reachedLufs.toFixed(1)} LUFS, ` +
`${(result.referenceLufs - result.reachedLufs).toFixed(1)} dB under the reference ` +
`(${LIMIT_TEXT[result.limitedBy]}).`,
);
}
@@ -229,7 +241,7 @@ function printMeasuredLine(result: NormalizeAudioResult): void {
const limit = result.limitedBy ? ` (${LIMIT_TEXT[result.limitedBy]})` : "";
console.log(
`${c.bold(`#${result.targetId}`)} ${result.sourceLufs.toFixed(1)} LUFS → ` +
`${result.projectedLufs.toFixed(1)} LUFS, target ${result.targetLufs.toFixed(1)}${limit}`,
`${result.reachedLufs.toFixed(1)} LUFS, target ${result.targetLufs.toFixed(1)}${limit}`,
);
}
@@ -242,7 +254,7 @@ function printHumanResult(result: NormalizeAudioResult): void {
return;
}
if (result.previousVolume > 0 && heldAtLimit(result, result.tolerance)) {
if (result.heldByLimit) {
console.log(c.dim("Cannot get closer to the target; the gain is unchanged."));
return;
}