mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-21 18:48:36 +00:00
change to bus effect experiment
This commit is contained in:
parent
a9efda3bc3
commit
9cbf3079f3
@ -382,15 +382,25 @@ const generic_params = [
|
|||||||
['coarse'],
|
['coarse'],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fake-resampling for lowering the sample rate. Caution: This effect seems to only work in chromium based browsers
|
* Phaser audio effect that approximates popular guitar pedals.
|
||||||
*
|
*
|
||||||
* @name phaser
|
* @name phaser
|
||||||
* @param {number | Pattern} factor 1 for original 2 for half, 3 for a third and so on.
|
* @param {number | Pattern} speed speed of modulation
|
||||||
* @example
|
* @example
|
||||||
* s("bd sd,hh*4").coarse("<1 4 8 16 32>")
|
* run(8).scale("D:pentatonic").note().sound("sawtooth").phaser("2 8").release(0.5)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
['phaser'],
|
['phaser'],
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @name phaserDepth
|
||||||
|
* @param {number | Pattern} depth number between 0 and 1
|
||||||
|
* @example
|
||||||
|
* run(8).scale("D:pentatonic").note().sound("sawtooth").phaser("2 8").phaserDepth(0.5).release(0.5)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
['phaserDepth'],
|
||||||
/**
|
/**
|
||||||
* choose the channel the pattern is sent to in superdirt
|
* choose the channel the pattern is sent to in superdirt
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
const createFilter = (ctx, cutoff, Q) => {
|
const createFilter = (ctx, cutoff, Q) => {
|
||||||
const lowpassFilter = ctx.createBiquadFilter();
|
const filter = ctx.createBiquadFilter();
|
||||||
lowpassFilter.type = 'notch';
|
filter.type = 'notch';
|
||||||
lowpassFilter.gain.value = 1;
|
filter.gain.value = 1;
|
||||||
lowpassFilter.frequency.value = cutoff;
|
filter.frequency.value = cutoff;
|
||||||
lowpassFilter.Q.value = Q;
|
filter.Q.value = Q;
|
||||||
return lowpassFilter;
|
return filter;
|
||||||
};
|
};
|
||||||
|
|
||||||
const createOscillator = (ctx, freq) => {
|
const createOscillator = (ctx, freq) => {
|
||||||
@ -26,12 +26,15 @@ const createLFO = (ctx, freq, gain) => {
|
|||||||
osc.connect(gainNode);
|
osc.connect(gainNode);
|
||||||
return gainNode;
|
return gainNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof GainNode !== 'undefined') {
|
if (typeof GainNode !== 'undefined') {
|
||||||
class PhaserNode extends GainNode {
|
class PhaserNode extends GainNode {
|
||||||
constructor(ac, speed, cps) {
|
constructor(ac, input) {
|
||||||
super(ac);
|
super(ac);
|
||||||
this.lfo;
|
this.lfo;
|
||||||
console.log(cps);
|
|
||||||
|
const { speed, depth = 0.5 } = input;
|
||||||
|
console.log(depth);
|
||||||
|
|
||||||
const makeupGain = ac.createGain();
|
const makeupGain = ac.createGain();
|
||||||
|
|
||||||
@ -43,7 +46,7 @@ if (typeof GainNode !== 'undefined') {
|
|||||||
for (let i = 0; i < numStages; i++) {
|
for (let i = 0; i < numStages; i++) {
|
||||||
const gain = ac.createGain();
|
const gain = ac.createGain();
|
||||||
gain.gain.value = 1 / numStages;
|
gain.gain.value = 1 / numStages;
|
||||||
const filter = createFilter(ac, 1000 + fOffset, 0.5);
|
const filter = createFilter(ac, 1000 + fOffset, 2 - Math.min(Math.max(depth * 2, 0), 1.9));
|
||||||
this.connect(filter);
|
this.connect(filter);
|
||||||
this.lfo.connect(filter.detune);
|
this.lfo.connect(filter.detune);
|
||||||
filter.connect(gain);
|
filter.connect(gain);
|
||||||
|
|||||||
@ -113,6 +113,71 @@ function getDelay(orbit, delaytime, delayfeedback, t) {
|
|||||||
return delays[orbit];
|
return delays[orbit];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const createFilter2 = (ctx, cutoff, Q) => {
|
||||||
|
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) => {
|
||||||
|
const osc = ctx.createOscillator();
|
||||||
|
osc.frequency.value = freq;
|
||||||
|
osc.type = 'sine';
|
||||||
|
return osc;
|
||||||
|
};
|
||||||
|
const createGain = (ctx, gain) => {
|
||||||
|
const gainNode = ctx.createGain();
|
||||||
|
gainNode.gain.value = gain;
|
||||||
|
return gainNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
const createLFO = (ctx, freq, gain) => {
|
||||||
|
const osc = createOscillator(ctx, freq);
|
||||||
|
const gainNode = createGain(ctx, gain);
|
||||||
|
osc.start();
|
||||||
|
osc.connect(gainNode);
|
||||||
|
return gainNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
// delays[orbit].delayTime.value !== delaytime && delays[orbit].delayTime.setValueAtTime(delaytime, t);
|
||||||
|
// delays[orbit].feedback.value !== delayfeedback && delays[orbit].feedback.setValueAtTime(delayfeedback, t);
|
||||||
|
return phasers[orbit];
|
||||||
|
}
|
||||||
|
|
||||||
let reverbs = {};
|
let reverbs = {};
|
||||||
|
|
||||||
let hasChanged = (now, before) => now !== undefined && now !== before;
|
let hasChanged = (now, before) => now !== undefined && now !== before;
|
||||||
@ -230,6 +295,7 @@ export const superdough = async (value, deadline, hapDuration) => {
|
|||||||
|
|
||||||
//phaser
|
//phaser
|
||||||
phaser,
|
phaser,
|
||||||
|
phaserDepth,
|
||||||
//
|
//
|
||||||
coarse,
|
coarse,
|
||||||
crush,
|
crush,
|
||||||
@ -365,10 +431,10 @@ export const superdough = async (value, deadline, hapDuration) => {
|
|||||||
chain.push(vowelFilter);
|
chain.push(vowelFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (phaser !== undefined) {
|
// if (phaser !== undefined) {
|
||||||
const phaserFX = ac.createPhaser(phaser, hapDuration);
|
// const phaserFX = ac.createPhaser({ speed: phaser, depth: phaserDepth });
|
||||||
chain.push(phaserFX);
|
// chain.push(phaserFX);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// effects
|
// effects
|
||||||
coarse !== undefined && chain.push(getWorklet(ac, 'coarse-processor', { coarse }));
|
coarse !== undefined && chain.push(getWorklet(ac, 'coarse-processor', { coarse }));
|
||||||
@ -393,6 +459,12 @@ export const superdough = async (value, deadline, hapDuration) => {
|
|||||||
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) {
|
||||||
@ -429,7 +501,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([delaySend, reverbSend, analyserSend]);
|
toDisconnect = chain.concat([phaserSend, 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);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user