mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-14 07:08:30 +00:00
latency :(
This commit is contained in:
parent
f1eaa83af5
commit
0c7b731fa6
@ -21,7 +21,7 @@ let interval = 0.1;
|
||||
//{type: 'log', payload: {type, text}}
|
||||
|
||||
const getTime = () => {
|
||||
return performance.now();
|
||||
return performance.now() / 1000;
|
||||
};
|
||||
|
||||
const sendMessage = (message) => {
|
||||
@ -52,7 +52,7 @@ let clock = createClock(
|
||||
lastEnd = end;
|
||||
const tickdeadline = phase - time; // time left until the phase is a whole number
|
||||
lastTick = time + tickdeadline;
|
||||
sendMessage({ type: 'tick', payload: { begin, end, tickdeadline } });
|
||||
sendMessage({ type: 'tick', payload: { begin, end, tickdeadline, cps, time: Date.now() } });
|
||||
} catch (e) {
|
||||
log(`[cyclist] error: ${e.message}`, 'error');
|
||||
}
|
||||
@ -77,7 +77,6 @@ self.onconnect = function (e) {
|
||||
};
|
||||
|
||||
const processMessage = (message) => {
|
||||
console.log(message);
|
||||
const { type, payload } = message;
|
||||
|
||||
switch (type) {
|
||||
@ -125,6 +124,7 @@ function createClock(
|
||||
if (phase === 0) {
|
||||
phase = t + minLatency;
|
||||
}
|
||||
console.log({ t, phase, tick });
|
||||
// callback as long as we're inside the lookahead
|
||||
while (phase < lookahead) {
|
||||
phase = Math.round(phase * precision) / precision;
|
||||
|
||||
@ -12,18 +12,20 @@ export class NeoCyclist {
|
||||
this.worker = new SharedWorker(new URL('./cyclistworker.js', import.meta.url));
|
||||
this.worker.port.start();
|
||||
this.worker.port.addEventListener('message', (message) => {
|
||||
console.log(message);
|
||||
const { payload, type } = message;
|
||||
const { payload, type } = message.data;
|
||||
|
||||
switch (type) {
|
||||
case 'tick': {
|
||||
console.log('tick');
|
||||
const { begin, end } = payload;
|
||||
let { begin, end, cps, tickdeadline, time } = payload;
|
||||
const messageLatency = (Date.now() - time) / 1000;
|
||||
tickdeadline = tickdeadline - messageLatency;
|
||||
console.log({ begin, end });
|
||||
const haps = this.pattern.queryArc(begin, end);
|
||||
haps.forEach((hap) => {
|
||||
if (hap.part.begin.equals(hap.whole.begin)) {
|
||||
const deadline = (hap.whole.begin - begin) / this.cps + payload.deadline + latency;
|
||||
const duration = hap.duration / this.cps;
|
||||
onTrigger?.(hap, deadline, duration, this.cps);
|
||||
const deadline = (hap.whole.begin - begin) / cps + tickdeadline + latency;
|
||||
const duration = hap.duration / cps;
|
||||
onTrigger?.(hap, deadline, duration, cps);
|
||||
}
|
||||
});
|
||||
break;
|
||||
@ -44,7 +46,7 @@ export class NeoCyclist {
|
||||
}
|
||||
|
||||
now() {
|
||||
return performance.now();
|
||||
return performance.now() / 1000;
|
||||
// this.sendMessage('requestcycles', {});
|
||||
}
|
||||
setCps(cps = 1) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user