mirror of
https://github.com/webadderallorg/Recordly.git
synced 2026-11-09 15:33:31 +00:00
fix(audio): deduplicate source track parser
This commit is contained in:
1 parent
7004723282
commit
84bb5b660a
2 files changed
+37
-8
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildResolvedAudioPlan, getSourceTrackIdFromPath } from "./audioRoutingEngine";
|
||||
|
||||
describe("getSourceTrackIdFromPath", () => {
|
||||
it.each([
|
||||
["/recordings/recording-mic.wav", "mic"],
|
||||
["/recordings/recording-system.wav", "system"],
|
||||
["/recordings/system.mp4", "system"],
|
||||
["/recordings/mic.wav", "mic"],
|
||||
])("classifies companion path %s as %s", (path, trackId) => {
|
||||
expect(getSourceTrackIdFromPath(path)).toBe(trackId);
|
||||
});
|
||||
|
||||
it("routes mic and system companions onto their dedicated playback tracks", () => {
|
||||
const plan = buildResolvedAudioPlan({
|
||||
videoResource: "/recordings/recording.mp4",
|
||||
sourceAudioFallbackPaths: [
|
||||
"/recordings/recording.mp4",
|
||||
"/recordings/recording-mic.wav",
|
||||
"/recordings/system.mp4",
|
||||
],
|
||||
});
|
||||
|
||||
expect(plan.pathsByTrack).toEqual({
|
||||
mic: "/recordings/recording-mic.wav",
|
||||
system: "/recordings/system.mp4",
|
||||
});
|
||||
expect(plan.playbackPaths).toEqual([
|
||||
"/recordings/system.mp4",
|
||||
"/recordings/recording-mic.wav",
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,10 @@
|
||||
import type { AudioRegion } from "@/components/video-editor/types";
|
||||
import { SOURCE_AUDIO_NORMALIZE_GAIN } from "@/components/video-editor/audio/audioTypes";
|
||||
import type { AudioRegion } from "@/components/video-editor/types";
|
||||
import { getSourceTrackIdFromPath } from "./audioProcessorShared";
|
||||
import { resolveSourceAudioFallbackPaths } from "./sourceAudioFallback";
|
||||
|
||||
export { getSourceTrackIdFromPath };
|
||||
|
||||
export type SourceTrackId = "mic" | "system" | "mixed";
|
||||
export type ResolvedAudioTrackKind = "user" | "system" | "mic" | "mixed" | "embedded";
|
||||
|
||||
@@ -29,13 +32,6 @@ export interface ResolvedAudioPlan {
|
||||
masterGain: number;
|
||||
}
|
||||
|
||||
export function getSourceTrackIdFromPath(audioPath: string): SourceTrackId {
|
||||
const normalized = audioPath.toLowerCase();
|
||||
if (normalized.includes(".mic.")) return "mic";
|
||||
if (normalized.includes(".system.")) return "system";
|
||||
return "mixed";
|
||||
}
|
||||
|
||||
function clampGain(value: number, max: number) {
|
||||
if (!Number.isFinite(value)) return 1;
|
||||
return Math.max(0, Math.min(max, value));
|
||||
|
||||
Reference in new issue
Block a user