From 3af2210c5ea67a93aa7592157d2f55ddfbdd2127 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Fri, 1 Apr 2022 17:42:52 +0200 Subject: [PATCH] remove pesky ticks and do it right --- packages/core/examples/metro.html | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/core/examples/metro.html b/packages/core/examples/metro.html index 645c0eb17..b8864be36 100644 --- a/packages/core/examples/metro.html +++ b/packages/core/examples/metro.html @@ -47,13 +47,15 @@ Loading... new Worker(urlifyFunction(func)); + const interval = 0.1; + const lookahead = 0.5; + // this class is basically the tale of two clocks class Metro { worker; audioContext; - startedAt = 0; interval = 0.2; // query span - tick = 0; + lastEnd = 0; constructor(audioContext, callback, interval = this.interval) { this.audioContext = audioContext; this.interval = interval; @@ -92,9 +94,9 @@ Loading... { if (e.data === 'tick') { - const begin = round(this.tick * this.interval, precision) + this.startedAt; // begin of tick - const end = round(begin + this.interval, precision); // end of tick - this.tick++; + const begin = this.lastEnd || this.audioContext.currentTime; + const end = this.audioContext.currentTime + this.interval; // DONT reference begin here! + this.lastEnd = end; // callback with query span, using clock #2 (the audio clock) callback(begin, end); } @@ -103,8 +105,6 @@ Loading... {