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

Function initialize

wasm/browser/src/workers/sab.worker.js:356–408  ·  view source on GitHub ↗
({ wasmDataURI, withPlugins = [], messagePort, callbackPort })

Source from the content-addressed store, hash-verified

354 };
355
356const 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
410export const sabWorker = { initialize, callUncloned };
411

Callers 2

SoundfileMethod · 0.50
closeMethod · 0.50

Calls 4

logFunction · 0.85
initCallbackReplyPortFunction · 0.85
csoundCreateMethod · 0.80
initMessagePortFunction · 0.70

Tested by

no test coverage detected