cleaning up

This commit is contained in:
Jade Rowland 2023-11-07 20:23:45 -05:00
parent 9cbf3079f3
commit 0edd54dee3

View File

@ -113,69 +113,46 @@ function getDelay(orbit, delaytime, delayfeedback, t) {
return delays[orbit]; return delays[orbit];
} }
const createFilter2 = (ctx, cutoff, Q) => { let phaserLFOs = {};
const filter = ctx.createBiquadFilter();
filter.type = 'notch';
filter.gain.value = 1;
filter.frequency.value = cutoff;
filter.Q.value = Q;
return filter;
};
const createOscillator = (ctx, freq) => { function getPhaser(orbit, speed = 1, depth = 0.5, t) {
const osc = ctx.createOscillator(); //gain
osc.frequency.value = freq; const ac = getAudioContext();
osc.type = 'sine'; const lfoGain = ac.createGain();
return osc; lfoGain.gain.value = 2000;
};
const createGain = (ctx, gain) => {
const gainNode = ctx.createGain();
gainNode.gain.value = gain;
return gainNode;
};
const createLFO = (ctx, freq, gain) => { //lfo
const osc = createOscillator(ctx, freq); if (phaserLFOs[orbit] == null) {
const gainNode = createGain(ctx, gain); const lfo = ac.createOscillator();
osc.start(); lfo.frequency.value = speed;
osc.connect(gainNode); lfo.type = 'sine';
return gainNode; lfo.start();
}; phaserLFOs[orbit] = lfo;
let phasers = {};
function getPhaser(orbit, speed = 1, depth = 0.5) {
if (!delays[orbit]) {
const ac = getAudioContext();
let lfo;
const makeupGain = ac.createGain();
if (lfo == null) {
lfo = createLFO(ac, speed, 2000);
}
const numStages = 2;
let fOffset = 0;
for (let i = 0; i < numStages; i++) {
const gain = ac.createGain();
gain.gain.value = 1 / numStages;
const filter = createFilter2(ac, 1000 + fOffset, 2 - Math.min(Math.max(depth * 2, 0), 1.9));
makeupGain.connect(filter);
lfo.connect(filter.detune);
filter.connect(gain);
gain.connect(makeupGain);
fOffset += 200 + Math.pow(i, 2);
}
makeupGain.gain.value = 1; // how much makeup gain to add?
makeupGain.connect(getDestination());
phasers[orbit] = makeupGain;
} }
console.log(phasers); if (phaserLFOs[orbit].frequency.value !== speed) {
// delays[orbit].delayTime.value !== delaytime && delays[orbit].delayTime.setValueAtTime(delaytime, t); phaserLFOs[orbit].frequency.setValueAtTime(speed, t);
// delays[orbit].feedback.value !== delayfeedback && delays[orbit].feedback.setValueAtTime(delayfeedback, t); }
return phasers[orbit]; phaserLFOs[orbit].connect(lfoGain);
//filters
const numStages = 2; //num of filters in series
let fOffset = 0;
const filterChain = [];
for (let i = 0; i < numStages; i++) {
const filter = ac.createBiquadFilter();
filter.type = 'notch';
filter.gain.value = 1;
filter.frequency.value = 1000 + fOffset;
filter.Q.value = 2 - Math.min(Math.max(depth * 2, 0), 1.9);
lfoGain.connect(filter.detune);
fOffset += 282;
if (i > 0) {
filterChain[i - 1].connect(filter);
}
filterChain.push(filter);
}
return filterChain[filterChain.length - 1];
} }
let reverbs = {}; let reverbs = {};
@ -453,18 +430,17 @@ export const superdough = async (value, deadline, hapDuration) => {
panner.pan.value = 2 * pan - 1; panner.pan.value = 2 * pan - 1;
chain.push(panner); chain.push(panner);
} }
// phaser
if (phaser !== undefined) {
const phaserFX = getPhaser(orbit, phaser, phaserDepth, t);
chain.push(phaserFX);
}
// last gain // last gain
const post = gainNode(postgain); const post = gainNode(postgain);
chain.push(post); chain.push(post);
post.connect(getDestination()); post.connect(getDestination());
let phaserSend;
if (phaser != null) {
const phaserFX = getPhaser(orbit, phaser, phaserDepth);
phaserSend = effectSend(post, phaserFX, 0.99);
}
// delay // delay
let delaySend; let delaySend;
if (delay > 0 && delaytime > 0 && delayfeedback > 0) { if (delay > 0 && delaytime > 0 && delayfeedback > 0) {
@ -501,7 +477,7 @@ export const superdough = async (value, deadline, hapDuration) => {
// toDisconnect = all the node that should be disconnected in onended callback // toDisconnect = all the node that should be disconnected in onended callback
// this is crucial for performance // this is crucial for performance
toDisconnect = chain.concat([phaserSend, delaySend, reverbSend, analyserSend]); toDisconnect = chain.concat([delaySend, reverbSend, analyserSend]);
}; };
export const superdoughTrigger = (t, hap, ct, cps) => superdough(hap, t - ct, hap.duration / cps, cps); export const superdoughTrigger = (t, hap, ct, cps) => superdough(hap, t - ct, hap.duration / cps, cps);