MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / startBoundedSource

Function startBoundedSource

packages/core/src/runtime/webAudioTransport.ts:33–57  ·  view source on GitHub ↗

* Start a buffer source, bounding it to the clip's authored window * (`data-duration`) so a trimmed clip stops at its edge instead of running the * buffer to the source file's natural end. `clipSourceLen` is the clip span in * buffer seconds; the third `start()` arg is the portion to play from th

(
  node: AudioBufferSourceNode,
  opts: {
    elapsed: number;
    mediaStart: number;
    scheduledAt: number;
    safeRate: number;
    clipDuration: number;
  },
)

Source from the content-addressed store, hash-verified

31 * play); the caller should discard the source.
32 */
33function startBoundedSource(
34 node: AudioBufferSourceNode,
35 opts: {
36 elapsed: number;
37 mediaStart: number;
38 scheduledAt: number;
39 safeRate: number;
40 clipDuration: number;
41 },
42): boolean {
43 const { elapsed, mediaStart, scheduledAt, safeRate, clipDuration } = opts;
44 const hasBound = Number.isFinite(clipDuration) && clipDuration > 0;
45 const clipSourceLen = clipDuration * safeRate;
46 if (elapsed >= 0) {
47 const remaining = clipSourceLen - elapsed;
48 if (hasBound && remaining <= 0) return false;
49 if (hasBound) node.start(0, elapsed + mediaStart, remaining);
50 else node.start(0, elapsed + mediaStart);
51 return true;
52 }
53 const delay = -elapsed / safeRate;
54 if (hasBound) node.start(scheduledAt + delay, mediaStart, clipSourceLen);
55 else node.start(scheduledAt + delay, mediaStart);
56 return true;
57}
58
59export type ScheduledSource = {
60 el: HTMLMediaElement;

Callers 1

schedulePlaybackMethod · 0.85

Calls 1

startMethod · 0.45

Tested by

no test coverage detected