This commit is contained in:
Jade (Rose) Rowland 2025-05-07 01:08:00 -04:00
parent 8d02d4270a
commit 56d3436fda

View File

@ -22,6 +22,12 @@ let maxPolyphony = DEFAULT_MAX_POLYPHONY;
export function setMaxPolyphony(polyphony) { export function setMaxPolyphony(polyphony) {
maxPolyphony = parseInt(polyphony) ?? DEFAULT_MAX_POLYPHONY; maxPolyphony = parseInt(polyphony) ?? DEFAULT_MAX_POLYPHONY;
} }
let multiChannelOrbits = false
export function setMultiChannelOrbits(bool) {
multiChannelOrbits = (bool == true);
}
export const soundMap = map(); export const soundMap = map();
export function registerSound(key, onTrigger, data = {}) { export function registerSound(key, onTrigger, data = {}) {
@ -195,7 +201,7 @@ function loadWorklets() {
// this function should be called on first user interaction (to avoid console warning) // this function should be called on first user interaction (to avoid console warning)
export async function initAudio(options = {}) { export async function initAudio(options = {}) {
const { disableWorklets = false, maxPolyphony, audioDeviceName = DEFAULT_AUDIO_DEVICE_NAME } = options; const { disableWorklets = false, maxPolyphony, audioDeviceName = DEFAULT_AUDIO_DEVICE_NAME, multiChannelOrbits = false } = options;
setMaxPolyphony(maxPolyphony); setMaxPolyphony(maxPolyphony);
if (typeof window === 'undefined') { if (typeof window === 'undefined') {
return; return;
@ -277,7 +283,7 @@ export const connectToDestination = (input, channels = [0, 1]) => {
}); });
stereoMix.connect(splitter); stereoMix.connect(splitter);
channels.forEach((ch, i) => { channels.forEach((ch, i) => {
splitter.connect(channelMerger, i % stereoMix.channelCount, clamp(ch, 0, ctx.destination.channelCount - 1)); splitter.connect(channelMerger, i % stereoMix.channelCount, ch % ctx.destination.channelCount);
}); });
}; };
@ -290,7 +296,7 @@ export const panic = () => {
channelMerger == null; channelMerger == null;
}; };
function getDelay(orbit, delaytime, delayfeedback, t) { function getDelay(orbit, delaytime, delayfeedback, t, channels) {
if (delayfeedback > maxfeedback) { if (delayfeedback > maxfeedback) {
//logger(`delayfeedback was clamped to ${maxfeedback} to save your ears`); //logger(`delayfeedback was clamped to ${maxfeedback} to save your ears`);
} }
@ -299,7 +305,7 @@ function getDelay(orbit, delaytime, delayfeedback, t) {
const ac = getAudioContext(); const ac = getAudioContext();
const dly = ac.createFeedbackDelay(1, delaytime, delayfeedback); const dly = ac.createFeedbackDelay(1, delaytime, delayfeedback);
dly.start?.(t); // for some reason, this throws when audion extension is installed.. dly.start?.(t); // for some reason, this throws when audion extension is installed..
connectToDestination(dly, [0, 1]); connectToDestination(dly, channels);
delays[orbit] = dly; delays[orbit] = dly;
} }
delays[orbit].delayTime.value !== delaytime && delays[orbit].delayTime.setValueAtTime(delaytime, t); delays[orbit].delayTime.value !== delaytime && delays[orbit].delayTime.setValueAtTime(delaytime, t);
@ -356,12 +362,12 @@ function getFilterType(ftype) {
let reverbs = {}; let reverbs = {};
let hasChanged = (now, before) => now !== undefined && now !== before; let hasChanged = (now, before) => now !== undefined && now !== before;
function getReverb(orbit, duration, fade, lp, dim, ir) { function getReverb(orbit, duration, fade, lp, dim, ir, channels) {
// If no reverb has been created for a given orbit, create one // If no reverb has been created for a given orbit, create one
if (!reverbs[orbit]) { if (!reverbs[orbit]) {
const ac = getAudioContext(); const ac = getAudioContext();
const reverb = ac.createReverb(duration, fade, lp, dim, ir); const reverb = ac.createReverb(duration, fade, lp, dim, ir);
connectToDestination(reverb, [0, 1]); connectToDestination(reverb, channels);
reverbs[orbit] = reverb; reverbs[orbit] = reverb;
} }
if ( if (
@ -490,7 +496,7 @@ export const superdough = async (value, t, hapDuration) => {
bpsustain, bpsustain,
bprelease, bprelease,
bandq = getDefaultValue('bandq'), bandq = getDefaultValue('bandq'),
channels = getDefaultValue('channels'),
//phaser //phaser
phaserrate: phaser, phaserrate: phaser,
phaserdepth = getDefaultValue('phaserdepth'), phaserdepth = getDefaultValue('phaserdepth'),
@ -526,6 +532,9 @@ export const superdough = async (value, t, hapDuration) => {
compressorRelease, compressorRelease,
} = value; } = value;
const orbitChannels = multiChannelOrbits ? [(orbit * 2) - 1, orbit * 2] : getDefaultValue('channels')
const channels = value.channels ?? orbitChannels;
gain = applyGainCurve(nanFallback(gain, 1)); gain = applyGainCurve(nanFallback(gain, 1));
postgain = applyGainCurve(postgain); postgain = applyGainCurve(postgain);
shapevol = applyGainCurve(shapevol); shapevol = applyGainCurve(shapevol);
@ -699,7 +708,7 @@ export const superdough = async (value, t, hapDuration) => {
// delay // delay
let delaySend; let delaySend;
if (delay > 0 && delaytime > 0 && delayfeedback > 0) { if (delay > 0 && delaytime > 0 && delayfeedback > 0) {
const delyNode = getDelay(orbit, delaytime, delayfeedback, t); const delyNode = getDelay(orbit, delaytime, delayfeedback, t, orbitChannels);
delaySend = effectSend(post, delyNode, delay); delaySend = effectSend(post, delyNode, delay);
audioNodes.push(delaySend); audioNodes.push(delaySend);
} }
@ -717,7 +726,7 @@ export const superdough = async (value, t, hapDuration) => {
} }
roomIR = await loadBuffer(url, ac, ir, 0); roomIR = await loadBuffer(url, ac, ir, 0);
} }
const reverbNode = getReverb(orbit, roomsize, roomfade, roomlp, roomdim, roomIR); const reverbNode = getReverb(orbit, roomsize, roomfade, roomlp, roomdim, roomIR, orbitChannels);
reverbSend = effectSend(post, reverbNode, room); reverbSend = effectSend(post, reverbNode, room);
audioNodes.push(reverbSend); audioNodes.push(reverbSend);
} }