-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessor.js
More file actions
26 lines (24 loc) · 808 Bytes
/
processor.js
File metadata and controls
26 lines (24 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Processor extends AudioWorkletProcessor {
static get parameterDescriptors() {
return [];
}
constructor(options) {
super(options);
const { dataSAB, pointerSAB, writePtr, readPtr } = options.processorOptions;
// this.dataSAB = dataSAB;
this.dataSAB = new Float32Array(dataSAB);
// this.pointerSAB = new Uint32Array(pointerSAB);
this.writePtr = writePtr;
this.readPtr = readPtr;
}
process(_input, outputs, _parameters) {
for (let i = 0; i < 128; i++) {
const readIndex = Atomics.load(this.readPtr, 0);
const writeIndex = Atomics.load(this.writePtr, 0);
outputs[0][0][i] = this.dataSAB [readIndex];
Atomics.store(this.readPtr, 0, (readIndex + 1) % 2048);
}
return true;
}
}
registerProcessor("processor", Processor);