Init commit

This commit is contained in:
Raphaël Forment
2023-07-28 01:23:38 +02:00
committed by GitHub
parent c34ee20306
commit aff5e643ac
20 changed files with 3848 additions and 0 deletions

37
src/TransportProcessor.js Normal file
View File

@ -0,0 +1,37 @@
class TransportProcessor extends AudioWorkletProcessor {
constructor(options) {
super(options);
this.port.addEventListener("message", this.handleMessage);
this.port.start();
this.interval = 0.001;
this.origin = currentTime;
this.next = this.origin + this.interval;
}
handleMessage = (message) => {
if (message.data === "start") {
this.origin = currentTime;
this.next = this.origin + this.interval;
} else if (message.data === "pause") {
this.next = Infinity;
} else if (message.data === "stop") {
this.origin = currentTime;
this.next = Infinity;
}
};
process(inputs, outputs, parameters) {
if (currentTime >= this.next) {
while (this.next < currentTime)
this.next += this.interval;
this.port.postMessage("bang");
}
return true;
}
}
registerProcessor(
"transport",
TransportProcessor
);