forked from ChelseaKR/olive-bark-logger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.js
More file actions
15 lines (13 loc) · 760 Bytes
/
Copy pathclock.js
File metadata and controls
15 lines (13 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Pure clock mapping: AudioContext.currentTime is seconds elapsed since the context
// was created, not a wall-clock time. report.js and the CSV exports expect unix-epoch
// seconds (new Date(ev.start * 1000)). We capture one anchor at start and add it to
// every context time so stored events carry real timestamps. Numbers only; no audio.
// Anchor captured once at start: the epoch-seconds value that context-time 0 maps to.
// anchor = Date.now()/1000 - audioCtx.currentTime, so anchor + currentTime === now.
export function computeAnchor(nowMs, ctxTime) {
return nowMs / 1000 - ctxTime;
}
// Map an AudioContext.currentTime reading to unix-epoch seconds via the anchor.
export function toEpochSeconds(ctxTime, anchor) {
return anchor + ctxTime;
}