MCPcopy Create free account
hub / github.com/csound/csound / renderFunction

Function renderFunction

wasm/browser/src/workers/common.utils.js:58–78  ·  view source on GitHub ↗
({ libraryCsound, workerMessagePort, wasi })

Source from the content-addressed store, hash-verified

56
57export const renderFunction =
58 ({ libraryCsound, workerMessagePort, wasi }) =>
59 async ({ csound }) => {
60 const kr = libraryCsound.csoundGetKr(csound);
61 let lastResult = 0;
62 let cnt = 0;
63
64 while (
65 (workerMessagePort.vanillaWorkerState === "renderStarted" ||
66 workerMessagePort.workerState === "renderStarted") &&
67 lastResult === 0
68 ) {
69 lastResult = libraryCsound.csoundPerformKsmps(csound);
70 cnt += 1;
71
72 if (typeof setTimeout === "function" && lastResult === 0 && cnt % kr === 0) {
73 // this is immediately executed, but allows events to be picked up
74 await new Promise((resolve) => setTimeout(resolve, 0));
75 }
76 }
77 workerMessagePort.broadcastPlayState("renderEnded");
78 };

Callers 3

startMethod · 0.90
startHandlerFunction · 0.90
handleCsoundStartFunction · 0.70

Calls 1

setTimeoutFunction · 0.85

Tested by

no test coverage detected