dough as a singleton worklet with voice allocation

This commit is contained in:
Felix Roos 2025-06-05 09:54:44 +02:00
parent ff4b7ca171
commit 930dabe4d6
No known key found for this signature in database
3 changed files with 104 additions and 39 deletions

View file

@ -1,10 +1,27 @@
import { Pattern } from '@strudel/core';
import { connectToDestination, destroyAudioWorkletNode, getAudioContext, webAudioTimeout } from 'superdough';
import { connectToDestination, getAudioContext, getWorklet } from 'superdough';
let doughWorklet;
function initDoughWorklet() {
const ac = getAudioContext();
doughWorklet = getWorklet(
ac,
'dough-processor',
{},
{
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 ac = getAudioContext();
const release = getADSRValues(
[value.attack, value.decay, value.sustain, value.release],
@ -17,19 +34,12 @@ Pattern.prototype.supradough = function () {
const end = holdEnd + release + 0.01;
value._begin = begin; // these are needed for the gate signal
value._end = end;
value._holdEnd = holdEnd
value._holdEnd = holdEnd;
value._holdDuration = duration + release;
let o = getWorklet(
ac,
'dough-processor',
{},
{
outputChannelCount: [2],
},
);
o.port.postMessage(value); // send value to worklet
webAudioTimeout(ac, () => destroyAudioWorkletNode(o), begin, end);
connectToDestination(o); // channels?
if (!doughWorklet) {
initDoughWorklet();
}
doughWorklet.port.postMessage(value);
}, 1);
};