Audio State and Gain Utilities (timeline/audio-state.ts)

opencut-classic · apps/web/src/timeline/audio-state.ts · typescript · MIT
ui, voice, files, lang:typescript, tag:multimedia, tag:math

Provides audio math utilities, decibel conversion, volume clamping, and automation helpers for timeline elements.

// Source: https://github.com/OpenCut-app/opencut-classic | License: MIT | Copyright 2025-2026 OpenCut
// Provided via justclaw.it.com; keep this notice with the code.
import { hasKeyframesForPath } from "@/animation/keyframe-query";
import { resolveNumberAtTime } from "@/animation/values";
import { VOLUME_DB_MAX, VOLUME_DB_MIN } from "./audio-constants";
import type { TimelineElement } from "./types";
const DEFAULT_STEP_SECONDS = 1 / 60;

export type AudioCapableElement = Extract<
	TimelineElement,
	{ type: "audio" | "video" }
>;

export function clampDb(value: number): number {
	if (!Number.isFinite(value)) {
		return 0;
	}

	return Math.min(VOLUME_DB_MAX, Math.max(VOLUME_DB_MIN, value));
}

export function dBToLinear(db: number): number {
	return 10 ** (clampDb(db) / 20);
}

export func

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key