mirror of
https://codeberg.org/uzu/strudel
synced 2026-08-10 16:09:35 -04:00
28 lines
826 B
JavaScript
28 lines
826 B
JavaScript
import { Dough } from './dough.mjs';
|
|
|
|
const clamp = (num, min, max) => Math.min(Math.max(num, min), max);
|
|
|
|
class DoughProcessor extends AudioWorkletProcessor {
|
|
constructor() {
|
|
super();
|
|
this.dough = new Dough(sampleRate, currentTime);
|
|
this.port.onmessage = (event) => this.dough.scheduleSpawn(event.data);
|
|
}
|
|
process(inputs, outputs, params) {
|
|
if (this.disconnected) {
|
|
return false;
|
|
}
|
|
const output = outputs[0];
|
|
for (let i = 0; i < output[0].length; i++) {
|
|
this.dough.update();
|
|
for (let c = 0; c < output.length; c++) {
|
|
//prevent speaker blowout via clipping if threshold exceeds
|
|
output[c][i] = clamp(this.dough.channels[c], -1, 1);
|
|
}
|
|
}
|
|
return true; // keep the audio processing going
|
|
}
|
|
}
|
|
|
|
registerProcessor('dough-processor', DoughProcessor);
|