prettier
This commit is contained in:
parent
ef6af96947
commit
d3733d4209
3 changed files with 7 additions and 56 deletions
|
|
@ -370,7 +370,7 @@ export function cycleToSeconds(cycle, cps) {
|
||||||
// utility for averaging two clocks together to account for drift
|
// utility for averaging two clocks together to account for drift
|
||||||
export class ClockCollator {
|
export class ClockCollator {
|
||||||
constructor({
|
constructor({
|
||||||
getTargetClockTime = () => Date.now() * 0.001,
|
getTargetClockTime = getUnixTimeSeconds,
|
||||||
weight = 16,
|
weight = 16,
|
||||||
offsetDelta = 0.005,
|
offsetDelta = 0.005,
|
||||||
checkAfterTime = 2,
|
checkAfterTime = 2,
|
||||||
|
|
@ -426,60 +426,12 @@ export class ClockCollator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// utility for averaging two clocks together to account for drift
|
export function getPerformanceTimeSeconds() {
|
||||||
export class ClockCollator {
|
return performance.now() * 0.001;
|
||||||
constructor({
|
|
||||||
getTargetClockTime = () => Date.now() / 1000,
|
|
||||||
weight = 16,
|
|
||||||
offsetDelta = 0.005,
|
|
||||||
checkAfterTime = 2,
|
|
||||||
resetAfterTime = 8,
|
|
||||||
}) {
|
|
||||||
this.offsetTime;
|
|
||||||
this.timeAtPrevOffsetSample;
|
|
||||||
this.prevOffsetTimes = [];
|
|
||||||
this.getTargetClockTime = getTargetClockTime;
|
|
||||||
this.weight = weight;
|
|
||||||
this.offsetDelta = offsetDelta;
|
|
||||||
this.checkAfterTime = checkAfterTime;
|
|
||||||
this.resetAfterTime = resetAfterTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
calculateTimestamp(currentTime, targetTime) {
|
|
||||||
const targetClockTime = this.getTargetClockTime();
|
|
||||||
const diffBetweenTimeSamples = targetClockTime - this.timeAtPrevOffsetSample;
|
|
||||||
const newOffsetTime = targetClockTime - currentTime;
|
|
||||||
// recalcuate the diff from scratch if the clock has been paused for some time.
|
|
||||||
if (diffBetweenTimeSamples > this.resetAfterTime) {
|
|
||||||
this.prevOffsetTimes = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.offsetTime == null) {
|
|
||||||
this.offsetTime = newOffsetTime;
|
|
||||||
}
|
|
||||||
this.prevOffsetTimes.push(newOffsetTime);
|
|
||||||
if (this.prevOffsetTimes.length > this.weight) {
|
|
||||||
this.prevOffsetTimes.shift();
|
|
||||||
}
|
|
||||||
|
|
||||||
// after X time has passed, the average of the previous weight offset times is calculated and used as a stable reference
|
|
||||||
// for calculating the timestamp
|
|
||||||
if (this.timeAtPrevOffsetSample == null || diffBetweenTimeSamples > this.checkAfterTime) {
|
|
||||||
this.timeAtPrevOffsetSample = targetClockTime;
|
|
||||||
const rollingOffsetTime = averageArray(this.prevOffsetTimes);
|
|
||||||
//when the clock offsets surpass the delta, set the new reference time
|
|
||||||
if (Math.abs(rollingOffsetTime - this.offsetTime) > this.offsetDelta) {
|
|
||||||
this.offsetTime = rollingOffsetTime;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const timestamp = this.offsetTime + targetTime;
|
|
||||||
return timestamp;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPerformanceTimeSeconds() {
|
function getUnixTimeSeconds() {
|
||||||
return performance.now() / 1000;
|
return Date.now() * 0.001;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Floating point versions, see Fraction for rational versions
|
// Floating point versions, see Fraction for rational versions
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,9 @@ import { oscTriggerTauri } from '../desktopbridge/oscbridge.mjs';
|
||||||
import { isTauri } from '../desktopbridge/utils.mjs';
|
import { isTauri } from '../desktopbridge/utils.mjs';
|
||||||
import { oscTrigger } from './osc.mjs';
|
import { oscTrigger } from './osc.mjs';
|
||||||
|
|
||||||
|
|
||||||
const trigger = isTauri() ? oscTriggerTauri : oscTrigger;
|
const trigger = isTauri() ? oscTriggerTauri : oscTrigger;
|
||||||
|
|
||||||
export const superdirtOutput = (hap, deadline, hapDuration, cps, targetTime) => {
|
export const superdirtOutput = (hap, deadline, hapDuration, cps, targetTime) => {
|
||||||
const currentTime = performance.now() / 1000
|
const currentTime = performance.now() / 1000;
|
||||||
return trigger(null, hap, currentTime, cps, targetTime);
|
return trigger(null, hap, currentTime, cps, targetTime);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ export const getAudioContext = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getAudioContextCurrentTime() {
|
export function getAudioContextCurrentTime() {
|
||||||
return getAudioContext().currentTime
|
return getAudioContext().currentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
let workletsLoading;
|
let workletsLoading;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue