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

Function processSharedArrayBuffer

wasm/browser/src/workers/worklet.worker.js:12–114  ·  view source on GitHub ↗
(inputs, outputs)

Source from the content-addressed store, hash-verified

10const activeNodes = new Map();
11
12function processSharedArrayBuffer(inputs, outputs) {
13 const isPerforming = Atomics.load(this.sharedArrayBuffer, AUDIO_STATE.IS_PERFORMING) === 1;
14 const isPaused = Atomics.load(this.sharedArrayBuffer, AUDIO_STATE.IS_PAUSED) === 1;
15 const isStopped = Atomics.load(this.sharedArrayBuffer, AUDIO_STATE.STOP) === 1;
16
17 if (this.startPromiz) {
18 this.startPromiz();
19 delete this.startPromiz;
20 }
21
22 if (!this.sharedArrayBuffer || isPaused || !isPerforming || isStopped) {
23 this.isPerformingLastTime = isPerforming;
24 this.firstBufferReady = false;
25 this.notifiedOnce = false;
26 // this.preProcessCount = 0;
27
28 // Fix for that chrome 64 bug which doesn't 0 the arrays
29 // https://github.com/csound/web-ide/issues/102#issuecomment-663894059
30 (outputs[0] || []).forEach((array) => array.fill(0));
31 return true;
32 }
33
34 this.isPerformingLastTime = isPerforming;
35
36 const writeableInputChannels = inputs && inputs[0];
37 const writeableOutputChannels = outputs && outputs[0];
38 const bufferLength = writeableOutputChannels[0].length;
39
40 if (this.bufferLength !== bufferLength) {
41 this.bufferLength = bufferLength;
42 Atomics.store(this.sharedArrayBuffer, AUDIO_STATE.BUFFER_LEN, bufferLength);
43 }
44
45 const nextInputWriteIndex =
46 writeableInputChannels && writeableInputChannels.length > 0
47 ? (this.inputWriteIndex + bufferLength) % RING_BUFFER_SIZE
48 : 0;
49
50 const nextOutputReadIndex =
51 writeableOutputChannels && writeableOutputChannels.length > 0
52 ? (this.outputReadIndex + bufferLength) % RING_BUFFER_SIZE
53 : 0;
54
55 if (Atomics.load(this.sharedArrayBuffer, AUDIO_STATE.AVAIL_OUT_BUFS) >= bufferLength) {
56 this.bufferUnderrunCount && (this.bufferUnderrunCount = 0);
57 writeableOutputChannels.forEach((channelBuffer, channelIndex) => {
58 // a simple set, where the len is the destination size and 2nd arg the offset
59
60 channelBuffer.set(
61 this.sabOutputChannels[channelIndex].subarray(
62 this.outputReadIndex,
63 nextOutputReadIndex < this.outputReadIndex ? RING_BUFFER_SIZE : nextOutputReadIndex,
64 ),
65 );
66 });
67
68 if (
69 writeableInputChannels &&

Callers

nothing calls this directly

Calls 2

loadMethod · 0.80
logMethod · 0.45

Tested by

no test coverage detected