({ libraryCsound, workerMessagePort, wasi })
| 56 | |
| 57 | export 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 | }; |
no test coverage detected