mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:00:07 +00:00
* feat(studio): audio level meters at the timeline's right edge * test(core): cover metering started before the audio context finishes init * fix(studio): keep meter follow after a dead preview and start bars at silence * fix(studio): keep the 0 dB peak tick inside the meter * fix(studio): keep the 0 dB peak tick visible without calc() * fix(core): tap meters on the program bus, mute on a monitor gain * style(core): wrap applyMasterGain to satisfy oxfmt
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
levelToFraction,
|
|
markFraction,
|
|
SILENT_CHANNEL,
|
|
stepChannel,
|
|
stepPair,
|
|
} from "./audioMeterMath";
|
|
|
|
describe("levelToFraction", () => {
|
|
it("puts each dB mark on its equally spaced stop", () => {
|
|
[1, 0.8, 0.6, 0.4, 0.2].forEach((f, i) =>
|
|
expect(markFraction([0, -3, -6, -12, -24][i]!)).toBeCloseTo(f, 6),
|
|
);
|
|
});
|
|
it("clamps silence and overs", () => {
|
|
expect(levelToFraction(0)).toBe(0);
|
|
expect(levelToFraction(4)).toBe(1);
|
|
});
|
|
it("is monotonic between marks", () => {
|
|
expect(levelToFraction(0.5)).toBeGreaterThan(markFraction(-12));
|
|
expect(levelToFraction(0.5)).toBeLessThan(markFraction(-3));
|
|
});
|
|
});
|
|
|
|
describe("stepChannel", () => {
|
|
it("attacks instantly, holds the peak, then falls", () => {
|
|
let ch = stepChannel(SILENT_CHANNEL, 1, 0, 16);
|
|
expect(ch.level).toBe(1);
|
|
ch = stepChannel(ch, 0, 500, 16);
|
|
expect(ch.peak).toBe(1);
|
|
expect(ch.level).toBeLessThan(1);
|
|
ch = stepChannel(ch, 0, 2000, 500);
|
|
expect(ch.peak).toBeLessThan(1);
|
|
});
|
|
});
|
|
|
|
describe("stepPair", () => {
|
|
it("returns the same pair while silent at rest, and moves on sound", () => {
|
|
const rest = stepPair(undefined, undefined, 0, 16);
|
|
expect(stepPair(rest, { l: 0, r: 0 }, 16, 16)).toBe(rest);
|
|
expect(stepPair(rest, { l: 1, r: 0 }, 32, 16)).not.toBe(rest);
|
|
});
|
|
});
|