A bit more cleanup

This commit is contained in:
Aria 2025-09-25 00:36:28 -07:00
parent bd8d207a3d
commit 96981c3c1d
2 changed files with 11 additions and 22 deletions

View file

@ -114,7 +114,7 @@ export const { wtWarp, wavetableWarp } = registerControl('wtWarp', 'wavetableWar
* spin, chaos, primes, binary, brownian, reciprocal, wormhole, logistic, sigmoid, fractal, flip * spin, chaos, primes, binary, brownian, reciprocal, wormhole, logistic, sigmoid, fractal, flip
* *
* @name wtWarpMode * @name wtWarpMode
* @param {number | Pattern} mode Warp mode * @param {number | string | Pattern} mode Warp mode
* @synonyms wavetableWarpMode * @synonyms wavetableWarpMode
* *
*/ */

View file

@ -182,20 +182,19 @@ export const tables = async (url, frameLen, json) => {
}; };
async function onTriggerSynth(t, value, onended, bank, frameLen) { async function onTriggerSynth(t, value, onended, bank, frameLen) {
let { s, n = 0, duration } = value; const { s, n = 0, duration } = value;
const ac = getAudioContext(); const ac = getAudioContext();
let [attack, decay, sustain, release] = getADSRValues([value.attack, value.decay, value.sustain, value.release]); const [attack, decay, sustain, release] = getADSRValues([value.attack, value.decay, value.sustain, value.release]);
let sourceDesc, holdEnd, envEnd;
let { wtWarpMode } = value; let { wtWarpMode } = value;
if (typeof wtWarpMode === 'string') { if (typeof wtWarpMode === 'string') {
wtWarpMode = WarpMode[wtWarpMode.toUpperCase()] ?? WarpMode.NONE; wtWarpMode = WarpMode[wtWarpMode.toUpperCase()] ?? WarpMode.NONE;
} }
const frequency = getFrequencyFromValue(value); const frequency = getFrequencyFromValue(value);
let { tableUrl, label } = getTableInfo(value, bank); const { tableUrl, label } = getTableInfo(value, bank);
const payload = await loadWavetableFrames(tableUrl, label, frameLen); const payload = await loadWavetableFrames(tableUrl, label, frameLen);
holdEnd = t + duration; const holdEnd = t + duration;
envEnd = holdEnd + release + 0.01; const envEnd = holdEnd + release;
const worklet = getWorklet( const source = getWorklet(
ac, ac,
'wavetable-oscillator-processor', 'wavetable-oscillator-processor',
{ {
@ -212,34 +211,24 @@ async function onTriggerSynth(t, value, onended, bank, frameLen) {
}, },
{ outputChannelCount: [2] }, { outputChannelCount: [2] },
); );
worklet.port.postMessage({ type: 'tables', payload }); source.port.postMessage({ type: 'tables', payload });
sourceDesc = { source: worklet };
const { source } = sourceDesc;
if (ac.currentTime > t) { if (ac.currentTime > t) {
logger(`[wavetable] still loading sound "${s}:${n}"`, 'highlight'); logger(`[wavetable] still loading sound "${s}:${n}"`, 'highlight');
return; return;
} }
if (!source) { const vibratoOscillator = getVibratoOscillator(source.detune, value, t);
logger(`[wavetable] could not load "${s}:${n}"`, 'error');
return;
}
let vibratoOscillator = getVibratoOscillator(source.detune, value, t);
const envGain = ac.createGain(); const envGain = ac.createGain();
const node = source.connect(envGain); const node = source.connect(envGain);
getParamADSR(node.gain, attack, decay, sustain, release, 0, 1, t, holdEnd, 'linear'); getParamADSR(node.gain, attack, decay, sustain, release, 0, 1, t, holdEnd, 'linear');
getPitchEnvelope(source.detune, value, t, holdEnd); getPitchEnvelope(source.detune, value, t, holdEnd);
const handle = { node, source };
const out = ac.createGain(); // we need a separate gain for the cutgroups because firefox... const timeoutNode = webAudioTimeout(
node.connect(out);
let handle = { node: out, bufferSource: source, oscillator: worklet };
let timeoutNode = webAudioTimeout(
ac, ac,
() => { () => {
source.disconnect(); source.disconnect();
destroyAudioWorkletNode(source); destroyAudioWorkletNode(source);
vibratoOscillator?.stop(); vibratoOscillator?.stop();
node.disconnect(); node.disconnect();
out.disconnect();
onended(); onended();
}, },
t, t,