diff options
| author | cashmere <cashmere@autistici.org> | 2026-08-16 06:16:56 +0200 |
|---|---|---|
| committer | cashmere <cashmere@autistici.org> | 2026-08-16 06:16:56 +0200 |
| commit | f1043734438c8518a302f698d9ae6583a75f0c14 (patch) | |
| tree | d3e636a96e6349c1ad17afa7b28c9ffe5c882e37 /apps/web/src/timeline/__tests__ | |
| parent | 37d22b1e390bd6cea04bf8e15069281ee125cf10 (diff) | |
| download | opencut-f1043734438c8518a302f698d9ae6583a75f0c14.tar.gz | |
feat: add transitions, track mixing, and voiceover controls
Diffstat (limited to 'apps/web/src/timeline/__tests__')
| -rw-r--r-- | apps/web/src/timeline/__tests__/audio-state.test.ts | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/apps/web/src/timeline/__tests__/audio-state.test.ts b/apps/web/src/timeline/__tests__/audio-state.test.ts new file mode 100644 index 00000000..91c422cb --- /dev/null +++ b/apps/web/src/timeline/__tests__/audio-state.test.ts @@ -0,0 +1,65 @@ +import { describe, expect, test } from "bun:test"; +import { + dBToLinear, + getTrackVolume, + resolveEffectiveAudioGain, +} from "@/timeline/audio-state"; +import type { AudioElement, AudioTrack } from "@/timeline"; +import { ZERO_MEDIA_TIME } from "@/wasm"; + +function audioElement(params?: AudioElement["params"]): AudioElement { + return { + id: "audio-1", + name: "Audio", + type: "audio", + sourceType: "upload", + mediaId: "media-1", + duration: ZERO_MEDIA_TIME, + startTime: ZERO_MEDIA_TIME, + trimStart: ZERO_MEDIA_TIME, + trimEnd: ZERO_MEDIA_TIME, + params: params ?? { volume: 0, muted: false }, + }; +} + +describe("audio state", () => { + test("track volume offsets element gain in decibels", () => { + const gain = resolveEffectiveAudioGain({ + element: audioElement({ volume: -6, muted: false }), + trackVolume: -6, + localTime: 0, + }); + + expect(gain).toBeCloseTo(dBToLinear(-12), 6); + }); + test("track volume and mute resolve to playback gain", () => { + const element = audioElement({ volume: 0, muted: false }); + + expect( + resolveEffectiveAudioGain({ element, trackVolume: 0, localTime: 0 }), + ).toBe(1); + expect( + resolveEffectiveAudioGain({ element, trackVolume: -6, localTime: 0 }), + ).toBeCloseTo(dBToLinear(-6), 6); + expect( + resolveEffectiveAudioGain({ + element, + trackMuted: true, + trackVolume: 0, + localTime: 0, + }), + ).toBe(0); + }); + + test("missing track volume defaults to unity", () => { + const track: AudioTrack = { + id: "track-1", + name: "Audio track", + type: "audio", + elements: [], + muted: false, + }; + + expect(getTrackVolume({ track })).toBe(0); + }); +}); |
