Clean up send nodes and remove offset

This commit is contained in:
Aria 2025-11-19 20:52:51 -06:00
parent 3e118ce0a8
commit 2794541dad
3 changed files with 11 additions and 123 deletions

View file

@ -3728,7 +3728,6 @@ addConfigAlias('send', 'id');
addConfigAlias('send', 'target', 't');
addConfigAlias('send', 'depth', 'dep', 'dp', 'd');
addConfigAlias('send', 'dc');
addConfigAlias('send', 'offset', 'off', 'o');
Pattern.prototype.modulate = function (type, config, idx) {
if (config == null || typeof config !== 'object') {
@ -3815,7 +3814,6 @@ export const env = (config) => pure({}).env(config);
* @param {string | Pattern} [config.target] Node (and parameter if specified like `lpf.frequency`) to modulate. Aliases: target, t
* @param {number | Pattern} [config.depth] Modulation depth. Aliases:dep, dp, d
* @param {number | Pattern} [config.dc] DC offset prior to application
* @param {number | Pattern} [config.offset] Offset to apply to the parameter. Aliases: off, o
* @param {number | null} idx Index of the send slot to overwrite. Omit to append a new send
* @returns Pattern
*/

View file

@ -481,14 +481,9 @@ function connectSendModulator(params, signal, nodeTracker, chainID) {
const ac = getAudioContext();
const dc = new ConstantSourceNode(ac, { offset: params.dc ?? 0 });
dc.start(params.begin);
const offset = new ConstantSourceNode(ac, { offset: params.offset ?? 0 });
offset.start(params.begin);
const raw = dc.connect(gainNode(1));
const modulator = signal
.connect(raw)
.connect(gainNode((params.depth ?? 1) / 0.3))
.connect(gainNode(1));
offset.connect(modulator);
const shifted = dc.connect(gainNode(1));
signal.connect(shifted);
const modulator = shifted.connect(gainNode((params.depth ?? 1) / 0.3));
webAudioTimeout(
ac,
() => {
@ -506,7 +501,7 @@ function connectSendModulator(params, signal, nodeTracker, chainID) {
0,
params.end + 0.05,
);
return modulator;
return { modulator, nodes: [dc, shifted, modulator] };
}
let activeSoundSources = new Map();
@ -978,7 +973,13 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
);
delete idToNodes[p.id];
} else {
const modulator = connectSendModulator({ ...p, begin: t, end: endWithRelease }, post, modNodes, chainID);
const { modulator, nodes: nodesToCleanup } = connectSendModulator(
{ ...p, begin: t, end: endWithRelease },
post,
modNodes,
chainID,
);
audioNodes = audioNodes.concat(nodesToCleanup);
pendingConnections[p.id] ??= {};
pendingConnections[p.id][chainID] = new WeakRef([modulator, p.target, endWithRelease]);
}