-
Notifications
You must be signed in to change notification settings - Fork 0
/
testprocessor.js
32 lines (27 loc) · 1012 Bytes
/
testprocessor.js
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
27
28
29
30
31
32
// https://stackoverflow.com/questions/11292076/load-audiodata-into-audiobuffersourcenode-from-audio-element-via-createmediae/70753627#70753627
class testprocessor extends AudioWorkletProcessor {
constructor(options) {
super();
console.log("constructing testprocessor");
this.port.onmessage = (e) => {
console.log(e.data);
};
}
// @ts-ignore
process(inputs, output, parameters) {
/**
* @type {Float32Array} length 128 Float32Array(128)
* non-interleaved IEEE754 32-bit linear PCM
* with a nominal range between -1 and +1,
* with each sample between -1.0 and 1.0.
* the sample rate depends on the audioContext and is variable
*/
const inputChannel = inputs[0][0]; //inputChannel Float32Array(128)
this.port.postMessage(inputChannel); // float32Array sent as byte[512]
if (inputChannel[0] != 0) {
console.log("audiobuffer ok");
}
return true; // always do this!
}
}
registerProcessor("testprocessor", testprocessor);