duckarray

This commit is contained in:
Jade (Rose) Rowland 2025-07-26 12:54:59 -04:00
parent 26225e4ea7
commit 51f0bab1f8
2 changed files with 14 additions and 10 deletions

View file

@ -535,7 +535,7 @@ export const { tremoloshape } = registerControl('tremoloshape', 'tremshape');
* stack( n(run(8)).scale("c:minor").s("sawtooth").delay(.7).orbit(2), s("bd:4!4").beat("0,4,8,11,14",16).duckorbit(2).duckattack(0.2).duckdepth(1))
*
*/
export const { duck } = registerControl(['duckorbit', 'duckattack', 'duckdepth'], 'duck');
export const { duck } = registerControl('duckorbit', 'duck');
/**
* the amount of ducking applied to target orbit

View file

@ -419,16 +419,20 @@ function setOrbit(audioContext, orbit, channels) {
connectToDestination(orbits[orbit].gain, channels);
}
}
function duckOrbit(target, t, attacktime = 0.1, duckdepth = 1) {
if (orbits[target] == null) {
errorLogger(new Error('duck target orbit does not exist'), 'superdough');
}
function duckOrbit(targetOrbit, t, attacktime = 0.1, duckdepth = 1) {
const targetArr = [targetOrbit].flat();
orbits[target].gain.gain.cancelAndHoldAtTime(t);
const currVal = orbits[target].gain.gain.value;
orbits[target].gain.gain.setValueAtTime(currVal, t);
orbits[target].gain.gain.linearRampToValueAtTime(clamp(1 - duckdepth, 0.01, currVal), t + 0.002);
orbits[target].gain.gain.exponentialRampToValueAtTime(1, t + Math.max(0.002, attacktime));
targetArr.forEach((target) => {
if (orbits[target] == null) {
errorLogger(new Error(`duck target orbit ${target} does not exist`), 'superdough');
return;
}
orbits[target].gain.gain.cancelAndHoldAtTime(t);
const currVal = orbits[target].gain.gain.value;
orbits[target].gain.gain.setValueAtTime(currVal, t);
orbits[target].gain.gain.linearRampToValueAtTime(clamp(1 - Math.pow(duckdepth, 0.5), 0.01, currVal), t + 0.002);
orbits[target].gain.gain.exponentialRampToValueAtTime(1, t + Math.max(0.002, attacktime));
});
}
let hasChanged = (now, before) => now !== undefined && now !== before;