Skip to content

The VS Code of video editing, built for agents.

TypeScript

Fix volume animation in audio panel to correctly ramp amplitude as decibels

konstantin-paulus92b923714040
diff --git a/packages/runtime/MIGRATION.md b/packages/runtime/MIGRATION.md
index 9b8fd6f5..33ae129f 100644
--- a/packages/runtime/MIGRATION.md
+++ b/packages/runtime/MIGRATION.md
@@ -109,7 +109,7 @@ The masks panel got shorter with the model. A mask is `<rect mask>`, a rect like
The audio panel kept its knob, meter and buttons; what moved is where they write. `volume` (decibels, unset at 0 since that is unity) and `muted` are props; **solo is not** — `Soloed` is a runtime-only tag with no JSX spelling, so the button writes the trait alone and the solo is gone on the next recompile, which is what a monitoring toggle should be. The knob writes whole decibels: it is what the field and the knob both display, and a dragged knob would otherwise mint a new fraction (and a new keyframe) per frame. The meter is unchanged, reading `AudioBusHandle` through `useTrait` (the playback system spins the bus up once the node has audio, and sets it back to null when the decoders are released, so the accessor holds null while the trait is still there).
-**Known bug, not this panel's**: the `gain` animation writes a 0-1 linear ramp into `Computed.volume` (`motion.ts`, `AnimationType.GAIN`), which everything else reads as decibels (`audio-bus.ts` does `10 ** (db / 20)`). So a Volume animation ramps 0 dB to 1 dB, which is inaudible, instead of silence to unity. Carried over from bitecs; the fix is in the motion system, not in the panel.
+Fixed while the panel moved: the `gain` animation used to write a 0-1 linear ramp into `Computed.volume`, which everything else reads as decibels (`audio-bus.ts` does `10 ** (db / 20)`), so a Volume animation ramped 0 dB to 1 dB, inaudibly, instead of silence to unity. It now ramps the *amplitude* and adds it to the volume as decibels (`amplitudeToDecibels`, -Infinity at silence, which the bus already reads as a gain of zero). Two consequences worth knowing: it reads `Computed.volume` instead of replacing it, unlike the visual presets, so a clip set to -6 dB fades to -6 dB rather than up to unity and an overlapping in and out compose; and a fade sounds even because it is even in amplitude, not in decibels.
The shadow panel kept the shape it had: a row per `<shadow>` opening a floating inspector, since nothing in the shadow model moved the way the stroke's line style did. The one thing it says that the file does not is what "Add shadow" authors (`opacity` 0.25, `blur` 4, `offsetY` 4): `<shadow>`'s own defaults are all zero, which casts the silhouette back onto itself, so a shadow added from the panel has to spell out where it sits. Every control unsets at the prop's default (0 for the offsets and the blur, 1 for opacity); `color` is required and always written.
diff --git a/packages/runtime/src/systems/motion.ts b/packages/runtime/src/systems/motion.ts
index cf982adf..6800d23b 100644
--- a/packages/runtime/src/systems/motion.ts
+++ b/packages/runtime/src/systems/motion.ts
@@ -88,7 +88,8 @@ function applyAnimation(world: World, entity: Entity, anim: Entity, progress: nu
const phase = animation.phase[aid];
const func = cubicBezier(0.4, 0.095, 0.546, 0.875);
const eased = clamp01(func(progress));
- computed.volume[eid] = phase === AnimationPhase.OUT ? 1 - eased : eased;
+ const amplitude = phase === AnimationPhase.OUT ? 1 - eased : eased;
+ computed.volume[eid] = (computed.volume[eid] ?? 0) + amplitudeToDecibels(amplitude);
break;
}
case AnimationType.GROW: {
@@ -493,6 +494,15 @@ function clamp01(value: number): number {
return Math.max(0, Math.min(1, value));
}
+/**
+ * An amplitude multiplier (0-1) as the decibels to add to a volume. Silence
+ * is -Infinity, which is what the audio bus reads as a gain of zero; every
+ * other value is negative, so a ramp only ever attenuates.
+ */
+function amplitudeToDecibels(amplitude: number): number {
+ return amplitude <= 0 ? -Infinity : 20 * Math.log10(amplitude);
+}
+
function lerp(from: number, to: number, progress: number): number {
return from + (to - from) * progress;
}