({ wasmDataURI, withPlugins = [], messagePort, callbackPort })
| 354 | }; |
| 355 | |
| 356 | const initialize = async ({ wasmDataURI, withPlugins = [], messagePort, callbackPort }) => { |
| 357 | log(`initializing SABWorker and WASM`)(); |
| 358 | const workerMessagePort = initMessagePort({ port: messagePort }); |
| 359 | const callbacksRequest = () => callbackPort.postMessage("poll"); |
| 360 | const releaseStop = () => callbackPort.postMessage("releaseStop"); |
| 361 | const releasePause = () => callbackPort.postMessage("releasePause"); |
| 362 | const releaseResumed = () => callbackPort.postMessage("releaseResumed"); |
| 363 | |
| 364 | initCallbackReplyPort({ port: callbackPort }); |
| 365 | |
| 366 | const [wasm, wasi] = await loadWasm({ |
| 367 | wasmDataURI, |
| 368 | withPlugins, |
| 369 | messagePort: workerMessagePort, |
| 370 | }); |
| 371 | |
| 372 | wasm.wasi = wasi; |
| 373 | |
| 374 | const libraryCsound = libcsoundFactory(wasm); |
| 375 | |
| 376 | const startHandler = (_, arguments_) => |
| 377 | handleCsoundStart( |
| 378 | workerMessagePort, |
| 379 | libraryCsound, |
| 380 | wasi, |
| 381 | sabCreateRealtimeAudioThread({ |
| 382 | libraryCsound, |
| 383 | callbacksRequest, |
| 384 | wasm, |
| 385 | workerMessagePort, |
| 386 | releaseStop, |
| 387 | releasePause, |
| 388 | releaseResumed, |
| 389 | }), |
| 390 | renderFunction({ |
| 391 | libraryCsound, |
| 392 | callbacksRequest, |
| 393 | workerMessagePort, |
| 394 | wasi, |
| 395 | releaseStop, |
| 396 | releasePause, |
| 397 | releaseResumed, |
| 398 | }), |
| 399 | )(arguments_); |
| 400 | |
| 401 | const allAPI = pipe(assoc("csoundStart", startHandler), assoc("wasm", wasm))(libraryCsound); |
| 402 | combined = new Map(Object.entries(allAPI)); |
| 403 | |
| 404 | libraryCsound.csoundInitialize(0); |
| 405 | const csoundInstance = libraryCsound.csoundCreate(); |
| 406 | |
| 407 | return csoundInstance; |
| 408 | }; |
| 409 | |
| 410 | export const sabWorker = { initialize, callUncloned }; |
| 411 |
no test coverage detected