From 73df344785a6c11a184c727b723e44e18068e5e3 Mon Sep 17 00:00:00 2001 From: mattk70 Date: Sun, 13 Oct 2024 16:51:47 +0100 Subject: [PATCH] More efficient backlog managment removed fullscreen from keyboard help --- Help/keyboard.html | 4 ---- js/worker.js | 21 +++++++-------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/Help/keyboard.html b/Help/keyboard.html index 4d2ceb7a..a04a9a0e 100644 --- a/Help/keyboard.html +++ b/Help/keyboard.html @@ -117,10 +117,6 @@ Ctrl-T Toggle between Timecode and Time of Day - - Ctrl-F - Toggle Fullscreen mode -
Records
diff --git a/js/worker.js b/js/worker.js index 40aaabdb..75db7618 100644 --- a/js/worker.js +++ b/js/worker.js @@ -20,12 +20,8 @@ const DEBUG = false; // Function to join Buffers and not use Buffer.concat() which leads to detached ArrayBuffers function joinBuffers(buffer1, buffer2) { // Create a new buffer with the combined length - const combinedBuffer = Buffer.alloc(buffer1.length + buffer2.length); - - // Copy buffer1 into the new buffer + const combinedBuffer = Buffer.allocUnsafe(buffer1.length + buffer2.length); buffer1.copy(combinedBuffer, 0); - - // Copy buffer2 into the new buffer, starting from the end of buffer1 buffer2.copy(combinedBuffer, buffer1.length); return combinedBuffer; } @@ -1294,24 +1290,21 @@ function setupCtx(audio, rate, destination, file) { function checkBacklog(stream) { - return new Promise((resolve, reject) => { + return new Promise((resolve) => { const backlog = sumObjectValues(predictionsRequested) - sumObjectValues(predictionsReceived); DEBUG && console.log('backlog:', backlog); - if (backlog >= predictWorkers.length * 4) { - // If queued value is above 100, wait and check again + if (backlog >= predictWorkers.length * 2) { + // If backlog is too high, check again after a short delay setTimeout(() => { - checkBacklog(stream) - .then(resolve) // Resolve the promise when backlog is within limit - .catch(reject); - }, 500); // Check every 0.5 seconds + resolve(checkBacklog(stream)); // Recursively call until backlog is within limits + }, 50); } else { - resolve(stream.read()); // backlog ok then read the stream data + resolve(stream.read()); // Backlog ok, read the stream data } }); } - /** * * @param file