refactor: make webaudio glue as minimal as possible

This commit is contained in:
Felix Roos 2025-06-05 10:26:14 +02:00
parent 930dabe4d6
commit 2cbd35f6d2
No known key found for this signature in database
2 changed files with 37 additions and 21 deletions

View file

@ -13,33 +13,17 @@ function initDoughWorklet() {
outputChannelCount: [2],
},
);
/* webAudioTimeout(ac, () => destroyAudioWorkletNode(doughWorklet), begin, end); */
connectToDestination(doughWorklet); // channels?
}
Pattern.prototype.supradough = function () {
return this.onTrigger((_, hap, __, cps, begin) => {
const { value } = hap;
// todo: could these calculations be made inside dough as well?
value.freq = getFrequencyFromValue(hap.value);
const release = getADSRValues(
[value.attack, value.decay, value.sustain, value.release],
'linear',
[0.001, 0.05, 0.6, 0.01],
)[3];
const duration = hap.duration / cps;
const holdEnd = begin + duration;
const end = holdEnd + release + 0.01;
value._begin = begin; // these are needed for the gate signal
value._end = end;
value._holdEnd = holdEnd;
value._holdDuration = duration + release;
hap.value._begin = begin;
hap.value._duration = hap.duration / cps;
if (!doughWorklet) {
initDoughWorklet();
}
doughWorklet.port.postMessage(value);
doughWorklet.port.postMessage(hap.value);
}, 1);
};