mirror of
https://codeberg.org/uzu/strudel
synced 2026-07-12 22:15:27 -04:00
Working version
This commit is contained in:
@@ -2846,6 +2846,7 @@ registerSubControls('lfo', [
|
||||
['skew', 'sk'],
|
||||
['curve'],
|
||||
['sync', 's'],
|
||||
['fxi'],
|
||||
]);
|
||||
registerSubControls('env', [
|
||||
['control', 'c'],
|
||||
@@ -2859,6 +2860,7 @@ registerSubControls('env', [
|
||||
['acurve', 'ac'],
|
||||
['dcurve', 'dc'],
|
||||
['rcurve', 'rc'],
|
||||
['fxi'],
|
||||
]);
|
||||
registerSubControls('bmod', [
|
||||
['bus', 'b'],
|
||||
@@ -2867,6 +2869,7 @@ registerSubControls('bmod', [
|
||||
['depth', 'dep', 'dr'],
|
||||
['depthabs', 'da'],
|
||||
['dc'],
|
||||
['fxi'],
|
||||
]);
|
||||
|
||||
Pattern.prototype.modulate = function (type, config, id) {
|
||||
@@ -2932,6 +2935,7 @@ Pattern.prototype.modulate = function (type, config, id) {
|
||||
* @param {number | Pattern} [config.skew] Skew amount. Aliases: sk
|
||||
* @param {number | Pattern} [config.curve] Exponential curve amount. Aliases: c
|
||||
* @param {number | Pattern} [config.sync] Tempo-synced modulation rate. Aliases: s
|
||||
* @param {number | Pattern} [config.fxi] FX index to target
|
||||
* @param {string | Pattern} id ID to use for this modulator
|
||||
* @returns Pattern
|
||||
*
|
||||
@@ -2985,6 +2989,7 @@ export const lfo = (config) => pure({}).lfo(config);
|
||||
* @param {number | Pattern} [config.acurve] Snappiness of attack curve (-1 = relaxed, 1 = snappy). Aliases: ac
|
||||
* @param {number | Pattern} [config.dcurve] Snappiness of decay curve (-1 = relaxed, 1 = snappy). Aliases: dc
|
||||
* @param {number | Pattern} [config.rcurve] Snappiness of release curve (-1 = relaxed, 1 = snappy). Aliases: rc
|
||||
* @param {number | Pattern} [config.fxi] FX index to target
|
||||
* @param {string | Pattern} id ID to use for this modulator
|
||||
* @returns Pattern
|
||||
*
|
||||
@@ -3039,6 +3044,7 @@ export const env = (config) => pure({}).env(config);
|
||||
* @param {number | Pattern} [config.depth] Relative modulation depth. Aliases: dep, dr
|
||||
* @param {number | Pattern} [config.depthabs] Absolute modulation depth. Aliases: da
|
||||
* @param {number | Pattern} [config.dc] DC offset prior to application
|
||||
* @param {number | Pattern} [config.fxi] FX index to target
|
||||
* @param {string | Pattern} id ID to use for this modulator
|
||||
* @returns Pattern
|
||||
*
|
||||
@@ -3065,3 +3071,5 @@ export const bmod = (config) => pure({}).bmod(config);
|
||||
* s("hh*16").bank("tr909").transient("<-1:1 1:-1>")
|
||||
*/
|
||||
export const { transient } = registerControl(['transient', 'transsustain']);
|
||||
|
||||
export const { FXrelease, FXrel, FXr, fxr } = registerControl('FXrelease', 'FXrel', 'FXr', 'fxr');
|
||||
|
||||
@@ -3721,3 +3721,19 @@ Pattern.prototype.phases = function (list) {
|
||||
export const phases = (list) => {
|
||||
return _ensureListPattern(list).as('phases');
|
||||
};
|
||||
|
||||
/**
|
||||
* Establishes an FX chain. Can be called by chaining .FX(<fx1>).FX(<fx2>)..
|
||||
* calls and/or in a single .FX(<fx1>, <fx2>, ..) call. The <fx1>, .. are _patterns_ which
|
||||
* establish the controls of the given effect. See examples.
|
||||
* @name FX
|
||||
* @memberof Pattern
|
||||
* @returns Pattern
|
||||
*/
|
||||
Pattern.prototype.FX = function (...effects) {
|
||||
effects = effects.map(reify);
|
||||
return this.withValue((v) => (vEff) => {
|
||||
const currFX = v.FX ?? [];
|
||||
return { ...v, FX: currFX.concat(vEff) };
|
||||
}).appLeft(parray(effects));
|
||||
};
|
||||
|
||||
@@ -5,19 +5,18 @@ if (typeof DelayNode !== 'undefined') {
|
||||
wet = Math.abs(wet);
|
||||
this.delayTime.value = time;
|
||||
|
||||
const feedbackGain = ac.createGain();
|
||||
feedbackGain.gain.value = Math.min(Math.abs(feedback), 0.995);
|
||||
this.feedback = feedbackGain.gain;
|
||||
this.feedbackGain = ac.createGain();
|
||||
this.feedbackGain.gain.value = Math.min(Math.abs(feedback), 0.995);
|
||||
this.feedback = this.feedbackGain.gain;
|
||||
|
||||
const delayGain = ac.createGain();
|
||||
delayGain.gain.value = wet;
|
||||
this.delayGain = delayGain;
|
||||
this.delayGain = ac.createGain();
|
||||
this.delayGain.gain.value = wet;
|
||||
|
||||
this.connect(feedbackGain);
|
||||
this.connect(delayGain);
|
||||
feedbackGain.connect(this);
|
||||
this.connect(this.feedbackGain);
|
||||
this.connect(this.delayGain);
|
||||
this.feedbackGain.connect(this);
|
||||
|
||||
this.connect = (target) => delayGain.connect(target);
|
||||
this.connect = (target) => this.delayGain.connect(target);
|
||||
return this;
|
||||
}
|
||||
start(t) {
|
||||
|
||||
@@ -85,8 +85,19 @@ const getTargetParamsForControl = (control, nodes, subControl) => {
|
||||
};
|
||||
|
||||
export const connectLFO = (id, params, nodeTracker) => {
|
||||
const { rate = 1, sync, cps, cycle, control = 'lfo', subControl, depth = 1, depthabs, ...filteredParams } = params;
|
||||
const { targetParams, paramName } = getTargetParamsForControl(control, nodeTracker, subControl);
|
||||
const {
|
||||
rate = 1,
|
||||
sync,
|
||||
cps,
|
||||
cycle,
|
||||
control = 'lfo',
|
||||
subControl,
|
||||
fxi = 'main',
|
||||
depth = 1,
|
||||
depthabs,
|
||||
...filteredParams
|
||||
} = params;
|
||||
const { targetParams, paramName } = getTargetParamsForControl(control, nodeTracker[fxi], subControl);
|
||||
if (!targetParams.length) return;
|
||||
let currentValue = targetParams[0].value;
|
||||
currentValue = currentValue === 0 ? 1 : currentValue;
|
||||
@@ -101,14 +112,14 @@ export const connectLFO = (id, params, nodeTracker) => {
|
||||
max,
|
||||
};
|
||||
const lfoNode = getLfo(getAudioContext(), modParams);
|
||||
nodeTracker[`lfo_${id}`] = [lfoNode];
|
||||
nodeTracker[0][`lfo_${id}`] = [lfoNode];
|
||||
targetParams.forEach((t) => lfoNode.connect(t));
|
||||
return lfoNode;
|
||||
};
|
||||
|
||||
export const connectEnvelope = (id, params, nodeTracker) => {
|
||||
const { control, subControl, acurve, dcurve, rcurve, depth = 1, depthabs, ...filteredParams } = params;
|
||||
const { targetParams, paramName } = getTargetParamsForControl(control, nodeTracker, subControl);
|
||||
const { control, subControl, acurve, dcurve, rcurve, depth = 1, depthabs, fxi = 'main', ...filteredParams } = params;
|
||||
const { targetParams, paramName } = getTargetParamsForControl(control, nodeTracker[fxi], subControl);
|
||||
if (!targetParams.length) return;
|
||||
let currentValue = targetParams[0].value;
|
||||
currentValue = currentValue === 0 ? 1 : currentValue;
|
||||
@@ -123,15 +134,15 @@ export const connectEnvelope = (id, params, nodeTracker) => {
|
||||
decayCurve: dcurve,
|
||||
releaseCurve: rcurve,
|
||||
});
|
||||
nodeTracker[`env_${id}`] = [envNode];
|
||||
nodeTracker[0][`env_${id}`] = [envNode];
|
||||
targetParams.forEach((t) => envNode.connect(t));
|
||||
return envNode;
|
||||
};
|
||||
|
||||
export const connectBusModulator = (params, nodeTracker, controller) => {
|
||||
const ac = getAudioContext();
|
||||
const { control, subControl, depth = 1, depthabs } = params;
|
||||
const { targetParams, paramName } = getTargetParamsForControl(control, nodeTracker, subControl);
|
||||
const { control, subControl, depth = 1, depthabs, fxi = 'main' } = params;
|
||||
const { targetParams, paramName } = getTargetParamsForControl(control, nodeTracker[fxi], subControl);
|
||||
if (!targetParams.length) return { toCleanup: [] };
|
||||
const signal = controller.getBus(params.bus);
|
||||
const dc = new ConstantSourceNode(ac, { offset: params.dc ?? 0 });
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { releaseAudioNode } from './helpers.mjs';
|
||||
|
||||
var reverbGen = {};
|
||||
|
||||
/** Generates a reverb impulse response.
|
||||
@@ -104,8 +106,8 @@ var applyGradualLowpass = function (input, lpFreqStart, lpFreqEnd, lpFreqEndAt,
|
||||
player.start();
|
||||
context.oncomplete = function (event) {
|
||||
callback(event.renderedBuffer);
|
||||
filter.disconnect();
|
||||
player.disconnect();
|
||||
releaseAudioNode(filter);
|
||||
releaseAudioNode(player);
|
||||
};
|
||||
context.startRendering();
|
||||
|
||||
|
||||
+416
-330
@@ -7,7 +7,7 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
import './feedbackdelay.mjs';
|
||||
import './reverb.mjs';
|
||||
import './vowel.mjs';
|
||||
import { nanFallback, _mod, cycleToSeconds, pickAndRename } from './util.mjs';
|
||||
import { clamp, nanFallback, _mod, cycleToSeconds, pickAndRename } from './util.mjs';
|
||||
import workletsUrl from './worklets.mjs?audioworklet';
|
||||
import {
|
||||
createFilter,
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
getLfo,
|
||||
getWorklet,
|
||||
releaseAudioNode,
|
||||
webAudioTimeout,
|
||||
} from './helpers.mjs';
|
||||
import { map } from 'nanostores';
|
||||
import { logger } from './logger.mjs';
|
||||
@@ -193,6 +194,8 @@ let defaultDefaultValues = {
|
||||
i: 1,
|
||||
velocity: 1,
|
||||
fft: 8,
|
||||
tremolodepth: 1,
|
||||
tremolophase: 0,
|
||||
};
|
||||
|
||||
const defaultDefaultDefaultValues = Object.freeze({ ...defaultDefaultValues });
|
||||
@@ -402,8 +405,37 @@ function mapChannelNumbers(channels) {
|
||||
return (Array.isArray(channels) ? channels : [channels]).map((ch) => ch - 1);
|
||||
}
|
||||
|
||||
class Chain {
|
||||
constructor(head) {
|
||||
this.audioNodes = [head];
|
||||
this.tails = [head];
|
||||
}
|
||||
connect(...nodes) {
|
||||
nodes.forEach((node) => {
|
||||
this.tails.forEach((tail) => {
|
||||
tail.connect(node);
|
||||
});
|
||||
});
|
||||
this.tails = nodes;
|
||||
this.audioNodes.push(...nodes);
|
||||
return this;
|
||||
}
|
||||
connectOne(idx, node) {
|
||||
this.tails[idx].connect(node);
|
||||
this.tails[idx] = node;
|
||||
this.audioNodes.push(node);
|
||||
return this;
|
||||
}
|
||||
releaseNodes() {
|
||||
this.audioNodes.forEach((n) => releaseAudioNode(n));
|
||||
this.audioNodes = [];
|
||||
this.tails = [];
|
||||
}
|
||||
}
|
||||
|
||||
export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5) => {
|
||||
let nodes = {};
|
||||
// mapping from main FX and numbered FX chains to nodes
|
||||
const nodes = { main: {} };
|
||||
// new: t is always expected to be the absolute target onset time
|
||||
const ac = getAudioContext();
|
||||
const audioController = getSuperdoughAudioController();
|
||||
@@ -432,44 +464,17 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
|
||||
}
|
||||
// destructure
|
||||
let {
|
||||
tremolo,
|
||||
tremolosync,
|
||||
tremolodepth = 1,
|
||||
tremoloskew,
|
||||
tremolophase = 0,
|
||||
tremoloshape,
|
||||
s = getDefaultValue('s'),
|
||||
bank,
|
||||
source,
|
||||
gain = getDefaultValue('gain'),
|
||||
postgain = getDefaultValue('postgain'),
|
||||
density = getDefaultValue('density'),
|
||||
duckorbit,
|
||||
duckonset,
|
||||
duckattack,
|
||||
duckdepth,
|
||||
djf,
|
||||
// filters
|
||||
fanchor = getDefaultValue('fanchor'),
|
||||
release = 0,
|
||||
|
||||
//phaser
|
||||
phaserrate,
|
||||
phaserdepth = getDefaultValue('phaserdepth'),
|
||||
phasersweep,
|
||||
phasercenter,
|
||||
//
|
||||
coarse,
|
||||
|
||||
crush,
|
||||
release = 0.01,
|
||||
dry,
|
||||
shape,
|
||||
shapevol = getDefaultValue('shapevol'),
|
||||
distort,
|
||||
distortvol = getDefaultValue('distortvol'),
|
||||
distorttype = getDefaultValue('distorttype'),
|
||||
pan,
|
||||
vowel,
|
||||
delay = getDefaultValue('delay'),
|
||||
delayfeedback = getDefaultValue('delayfeedback'),
|
||||
delaysync = getDefaultValue('delaysync'),
|
||||
@@ -486,16 +491,10 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
|
||||
irspeed,
|
||||
irbegin,
|
||||
i = getDefaultValue('i'),
|
||||
velocity = getDefaultValue('velocity'),
|
||||
analyze, // analyser wet
|
||||
fft = getDefaultValue('fft'), // fftSize 0 - 10
|
||||
compressor: compressorThreshold,
|
||||
compressorRatio,
|
||||
compressorKnee,
|
||||
compressorAttack,
|
||||
compressorRelease,
|
||||
transient,
|
||||
transsustain,
|
||||
FX = [],
|
||||
FXrelease,
|
||||
} = value;
|
||||
|
||||
delaytime = delaytime ?? cycleToSeconds(delaysync, cps);
|
||||
@@ -510,18 +509,13 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
|
||||
audioController.duck(duckorbit, t, duckonset, duckattack, duckdepth);
|
||||
}
|
||||
|
||||
gain = applyGainCurve(nanFallback(gain, 1));
|
||||
postgain = applyGainCurve(postgain);
|
||||
shapevol = applyGainCurve(shapevol);
|
||||
distortvol = applyGainCurve(distortvol);
|
||||
delay = applyGainCurve(delay);
|
||||
velocity = applyGainCurve(velocity);
|
||||
tremolodepth = applyGainCurve(tremolodepth);
|
||||
busgain = applyGainCurve(busgain);
|
||||
gain *= velocity; // velocity currently only multiplies with gain. it might do other things in the future
|
||||
|
||||
const end = t + hapDuration;
|
||||
const endWithRelease = end + release;
|
||||
const fullRelease = Math.max(release, FXrelease ?? 0);
|
||||
const endWithRelease = end + fullRelease;
|
||||
const chainID = Math.round(Math.random() * 1000000);
|
||||
|
||||
// oldest audio nodes will be destroyed if maximum polyphony is exceeded
|
||||
@@ -535,8 +529,6 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
|
||||
activeSoundSources.delete(chainID);
|
||||
}
|
||||
|
||||
const audioNodes = [];
|
||||
|
||||
if (['-', '~', '_'].includes(s)) {
|
||||
return;
|
||||
}
|
||||
@@ -549,19 +541,16 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
|
||||
let sourceNode;
|
||||
if (source) {
|
||||
sourceNode = source(t, value, hapDuration, cps);
|
||||
nodes['source'] = [sourceNode];
|
||||
nodes.main['source'] = [sourceNode];
|
||||
} else if (getSound(s)) {
|
||||
const { onTrigger } = getSound(s);
|
||||
const onEnded = () => {
|
||||
audioNodes.forEach((n) => releaseAudioNode(n));
|
||||
activeSoundSources.delete(chainID);
|
||||
};
|
||||
const onEnded = () => {};
|
||||
const soundHandle = await onTrigger(t, value, onEnded, cps);
|
||||
|
||||
if (soundHandle) {
|
||||
sourceNode = soundHandle.node;
|
||||
activeSoundSources.set(chainID, new WeakRef(soundHandle)); // allow GC
|
||||
nodes = { ...nodes, ...soundHandle.nodes };
|
||||
nodes.main = { ...nodes.main, ...soundHandle.nodes };
|
||||
}
|
||||
} else {
|
||||
throw new Error(`sound ${s} not found! Is it loaded?`);
|
||||
@@ -576,253 +565,339 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
|
||||
logger('[webaudio] skip hap: still loading', ac.currentTime - t);
|
||||
return;
|
||||
}
|
||||
const chain = []; // audio nodes that will be connected to each other sequentially
|
||||
chain.push(sourceNode);
|
||||
stretch !== undefined && chain.push(getWorklet(ac, 'phase-vocoder-processor', { pitchFactor: stretch }));
|
||||
|
||||
if (transient !== undefined) {
|
||||
const transProcessor = getWorklet(
|
||||
ac,
|
||||
'transient-processor',
|
||||
{},
|
||||
{
|
||||
processorOptions: {
|
||||
attack: transient,
|
||||
sustain: transsustain,
|
||||
begin: t,
|
||||
end: endWithRelease,
|
||||
const chain = new Chain(sourceNode); // audio nodes that will be connected to each other sequentially
|
||||
FX = [...FX, value]; // run through the FX chain and then run through all FX outside of it as well
|
||||
for (let [idx, fx] of Object.entries(FX)) {
|
||||
const key = idx == FX.length - 1 ? 'main' : idx;
|
||||
nodes[key] ??= {};
|
||||
const fxNodes = nodes[key];
|
||||
let {
|
||||
gain = getDefaultValue('gain'),
|
||||
velocity = getDefaultValue('velocity'),
|
||||
shapevol = getDefaultValue('shapevol'),
|
||||
distorttype = getDefaultValue('distorttype'),
|
||||
distortvol = getDefaultValue('distortvol'),
|
||||
tremolodepth = getDefaultValue('tremolodepth'),
|
||||
phaserdepth = getDefaultValue('phaserdepth'),
|
||||
delay = getDefaultValue('delay'),
|
||||
delayfeedback = getDefaultValue('delayfeedback'),
|
||||
delaysync = getDefaultValue('delaysync'),
|
||||
delaytime,
|
||||
stretch = getDefaultValue('stretch'),
|
||||
} = fx;
|
||||
gain = applyGainCurve(nanFallback(gain, 1));
|
||||
shapevol = applyGainCurve(shapevol);
|
||||
distortvol = applyGainCurve(distortvol);
|
||||
velocity = applyGainCurve(velocity);
|
||||
tremolodepth = applyGainCurve(tremolodepth);
|
||||
gain *= velocity; // velocity currently only multiplies with gain. it might do other things in the future
|
||||
delaytime = delaytime ?? cycleToSeconds(delaysync, cps);
|
||||
|
||||
stretch !== undefined && chain.connect(getWorklet(ac, 'phase-vocoder-processor', { pitchFactor: stretch }));
|
||||
|
||||
if (fx.transient !== undefined) {
|
||||
const transProcessor = getWorklet(
|
||||
ac,
|
||||
'transient-processor',
|
||||
{},
|
||||
{
|
||||
processorOptions: {
|
||||
attack: fx.transient,
|
||||
sustain: fx.transsustain,
|
||||
begin: t,
|
||||
end: endWithRelease,
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
chain.push(transProcessor);
|
||||
nodes['transient'] = transProcessor;
|
||||
}
|
||||
);
|
||||
chain.connect(transProcessor);
|
||||
fxNodes['transient'] = transProcessor;
|
||||
}
|
||||
|
||||
// gain stage
|
||||
const initialGain = gainNode(gain);
|
||||
nodes['gain'] = [initialGain];
|
||||
chain.push(initialGain);
|
||||
// gain stage
|
||||
const initialGain = gainNode(gain);
|
||||
fxNodes['gain'] = [initialGain];
|
||||
chain.connect(initialGain);
|
||||
|
||||
// filter
|
||||
const ftype = getFilterType(value.ftype);
|
||||
// filter
|
||||
const ftype = getFilterType(value.ftype);
|
||||
|
||||
const filt = (params) => createFilter(ac, t, end, params, cps, cycle);
|
||||
if (value.cutoff !== undefined) {
|
||||
const lpMap = {
|
||||
frequency: 'cutoff',
|
||||
q: 'resonance',
|
||||
attack: 'lpattack',
|
||||
decay: 'lpdecay',
|
||||
sustain: 'lpsustain',
|
||||
release: 'lprelease',
|
||||
env: 'lpenv',
|
||||
anchor: 'fanchor',
|
||||
model: 'ftype',
|
||||
drive: 'drive',
|
||||
rate: 'lprate',
|
||||
sync: 'lpsync',
|
||||
depth: 'lpdepth',
|
||||
depthfrequency: 'lpdepthfrequency',
|
||||
shape: 'lpshape',
|
||||
dcoffset: 'lpdc',
|
||||
skew: 'lpskew',
|
||||
};
|
||||
const lpParams = pickAndRename(value, lpMap);
|
||||
lpParams.type = 'lowpass';
|
||||
const { filter: lpf1, lfo: lfo1 } = filt(lpParams);
|
||||
nodes['lpf'] = [lpf1];
|
||||
nodes['lpf_lfo'] = [lfo1];
|
||||
chain.push(lpf1);
|
||||
lfo1 && audioNodes.push(lfo1);
|
||||
if (ftype === '24db') {
|
||||
const { filter: lpf2, lfo: lfo2 } = filt(lpParams);
|
||||
nodes['lpf'].push(lpf2);
|
||||
nodes['lpf_lfo'].push(lfo2);
|
||||
chain.push(lpf2);
|
||||
lfo2 && audioNodes.push(lfo2);
|
||||
const filt = (params) => createFilter(ac, t, end, params, cps, cycle);
|
||||
if (fx.cutoff !== undefined) {
|
||||
const lpMap = {
|
||||
frequency: 'cutoff',
|
||||
q: 'resonance',
|
||||
attack: 'lpattack',
|
||||
decay: 'lpdecay',
|
||||
sustain: 'lpsustain',
|
||||
release: 'lprelease',
|
||||
env: 'lpenv',
|
||||
anchor: 'fanchor',
|
||||
model: 'ftype',
|
||||
drive: 'drive',
|
||||
rate: 'lprate',
|
||||
sync: 'lpsync',
|
||||
depth: 'lpdepth',
|
||||
depthfrequency: 'lpdepthfrequency',
|
||||
shape: 'lpshape',
|
||||
dcoffset: 'lpdc',
|
||||
skew: 'lpskew',
|
||||
};
|
||||
const lpParams = pickAndRename(fx, lpMap);
|
||||
lpParams.type = 'lowpass';
|
||||
const { filter: lpf1, lfo: lfo1 } = filt(lpParams);
|
||||
fxNodes['lpf'] = [lpf1];
|
||||
fxNodes['lpf_lfo'] = [lfo1];
|
||||
chain.connect(lpf1);
|
||||
lfo1 && chain.audioNodes.push(lfo1);
|
||||
if (ftype === '24db') {
|
||||
const { filter: lpf2, lfo: lfo2 } = filt(lpParams);
|
||||
fxNodes['lpf'].push(lpf2);
|
||||
fxNodes['lpf_lfo'].push(lfo2);
|
||||
chain.connect(lpf2);
|
||||
lfo2 && chain.audioNodes.push(lfo2);
|
||||
}
|
||||
}
|
||||
|
||||
if (fx.hcutoff !== undefined) {
|
||||
const hpMap = {
|
||||
frequency: 'hcutoff',
|
||||
q: 'hresonance',
|
||||
attack: 'hpattack',
|
||||
decay: 'hpdecay',
|
||||
sustain: 'hpsustain',
|
||||
release: 'hprelease',
|
||||
env: 'hpenv',
|
||||
anchor: 'fanchor',
|
||||
model: 'ftype',
|
||||
drive: 'drive',
|
||||
rate: 'hprate',
|
||||
sync: 'hpsync',
|
||||
depth: 'hpdepth',
|
||||
depthfrequency: 'hpdepthfrequency',
|
||||
shape: 'hpshape',
|
||||
dcoffset: 'hpdc',
|
||||
skew: 'hpskew',
|
||||
};
|
||||
const hpParams = pickAndRename(fx, hpMap);
|
||||
hpParams.type = 'highpass';
|
||||
const { filter: hpf1, lfo: lfo1 } = filt(hpParams);
|
||||
fxNodes['hpf'] = [hpf1];
|
||||
fxNodes['hpf_lfo'] = [lfo1];
|
||||
lfo1 && chain.audioNodes.push(lfo1);
|
||||
chain.connect(hpf1);
|
||||
if (ftype === '24db') {
|
||||
const { filter: hpf2, lfo: lfo2 } = filt(hpParams);
|
||||
fxNodes['hpf'].push(hpf2);
|
||||
fxNodes['hpf_lfo'].push(lfo2);
|
||||
chain.connect(hpf2);
|
||||
lfo2 && chain.audioNodes.push(lfo2);
|
||||
}
|
||||
}
|
||||
|
||||
if (fx.bandf !== undefined) {
|
||||
const bpMap = {
|
||||
frequency: 'bandf',
|
||||
q: 'bandq',
|
||||
attack: 'bpattack',
|
||||
decay: 'bpdecay',
|
||||
sustain: 'bpsustain',
|
||||
release: 'bprelease',
|
||||
env: 'bpenv',
|
||||
anchor: 'fanchor',
|
||||
model: 'ftype',
|
||||
drive: 'drive',
|
||||
rate: 'bprate',
|
||||
sync: 'bpsync',
|
||||
depth: 'bpdepth',
|
||||
depthfrequency: 'bpdepthfrequency',
|
||||
shape: 'bpshape',
|
||||
dcoffset: 'bpdc',
|
||||
skew: 'bpskew',
|
||||
};
|
||||
const bpParams = pickAndRename(fx, bpMap);
|
||||
bpParams.type = 'bandpass';
|
||||
const { filter: bpf1, lfo: lfo1 } = filt(bpParams);
|
||||
fxNodes['bpf'] = [bpf1];
|
||||
fxNodes['bpf_lfo'] = [lfo1];
|
||||
chain.connect(bpf1);
|
||||
lfo1 && chain.audioNodes.push(lfo1);
|
||||
if (ftype === '24db') {
|
||||
const { filter: bpf2, lfo: lfo2 } = filt(bpParams);
|
||||
fxNodes['bpf'].push(bpf2);
|
||||
fxNodes['bpf_lfo'].push(lfo2);
|
||||
chain.connect(bpf2);
|
||||
lfo2 && chain.audioNodes.push(lfo2);
|
||||
}
|
||||
}
|
||||
|
||||
if (fx.vowel !== undefined) {
|
||||
const vowelFilter = ac.createVowelFilter(fx.vowel);
|
||||
fxNodes['vowel'] = [vowelFilter];
|
||||
chain.connect(vowelFilter);
|
||||
}
|
||||
|
||||
// effects
|
||||
if (fx.coarse !== undefined) {
|
||||
const coarseNode = getWorklet(ac, 'coarse-processor', { coarse: fx.coarse });
|
||||
fxNodes['coarse'] = [coarseNode];
|
||||
chain.connect(coarseNode);
|
||||
}
|
||||
if (fx.crush !== undefined) {
|
||||
const crushNode = getWorklet(ac, 'crush-processor', { crush: fx.crush });
|
||||
fxNodes['crush'] = [crushNode];
|
||||
chain.connect(crushNode);
|
||||
}
|
||||
if (fx.shape !== undefined) {
|
||||
const shapeNode = getWorklet(ac, 'shape-processor', { shape: fx.shape, postgain: shapevol });
|
||||
fxNodes['shape'] = [shapeNode];
|
||||
chain.connect(shapeNode);
|
||||
}
|
||||
if (fx.distort !== undefined) {
|
||||
const distortNode = getDistortion(fx.distort, distortvol, distorttype);
|
||||
fxNodes['distort'] = [distortNode];
|
||||
chain.connect(distortNode);
|
||||
}
|
||||
|
||||
let tremolo = fx.tremolo;
|
||||
if (fx.tremolosync != null) {
|
||||
tremolo = cps * fx.tremolosync;
|
||||
}
|
||||
|
||||
if (tremolo !== undefined) {
|
||||
// Allow clipping of modulator for more dynamic possiblities, and to prevent speaker overload
|
||||
// EX: a triangle waveform will clip like this /-\ when the depth is above 1
|
||||
const gain = Math.max(1 - tremolodepth, 0);
|
||||
const amGain = new GainNode(ac, { gain });
|
||||
|
||||
const time = cycle / cps;
|
||||
const lfo = getLfo(ac, {
|
||||
skew: fx.tremoloskew ?? (fx.tremoloshape != null ? 0.5 : 1),
|
||||
frequency: tremolo,
|
||||
depth: tremolodepth,
|
||||
time,
|
||||
dcoffset: 0,
|
||||
shape: fx.tremoloshape,
|
||||
phaseoffset: fx.tremolophase,
|
||||
min: 0,
|
||||
max: 1,
|
||||
curve: 1.5,
|
||||
begin: t,
|
||||
end: endWithRelease,
|
||||
});
|
||||
fxNodes['tremolo'] = [lfo];
|
||||
fxNodes['tremolo_gain'] = [amGain];
|
||||
lfo.connect(amGain.gain);
|
||||
chain.audioNodes.push(lfo);
|
||||
chain.connect(amGain);
|
||||
}
|
||||
|
||||
if (fx.compressor !== undefined) {
|
||||
const compressorNode = getCompressor(
|
||||
ac,
|
||||
fx.compressor,
|
||||
fx.compressorRatio,
|
||||
fx.compressorKnee,
|
||||
fx.compressorAttack,
|
||||
fx.compressorRelease,
|
||||
);
|
||||
fxNodes['compressor'] = [compressorNode];
|
||||
chain.connect(compressorNode);
|
||||
}
|
||||
|
||||
// panning
|
||||
if (fx.pan !== undefined) {
|
||||
const panner = ac.createStereoPanner();
|
||||
panner.pan.value = 2 * fx.pan - 1;
|
||||
chain.connect(panner);
|
||||
}
|
||||
// phaser
|
||||
if (fx.phaserrate !== undefined && phaserdepth > 0) {
|
||||
const { filterChain, lfo } = getPhaser(
|
||||
t,
|
||||
endWithRelease,
|
||||
fx.phaserrate,
|
||||
phaserdepth,
|
||||
fx.phasercenter,
|
||||
fx.phasersweep,
|
||||
);
|
||||
fxNodes['phaser'] = [...filterChain];
|
||||
fxNodes['phaser_lfo'] = [lfo];
|
||||
filterChain.forEach((f) => chain.connect(f));
|
||||
chain.audioNodes.push(lfo);
|
||||
}
|
||||
// delay
|
||||
if (delay > 0 && delaytime > 0 && delayfeedback > 0) {
|
||||
const dry = gainNode(1);
|
||||
delayfeedback = clamp(delayfeedback, 0, 0.98);
|
||||
const delayNode = ac.createFeedbackDelay(1, delaytime, delayfeedback);
|
||||
const wetDelay = gainNode(delay);
|
||||
const dryDelay = gainNode(fx.dry ?? 1);
|
||||
const sum = new GainNode(ac, { gain: 1, channelCount: 2, channelCountMode: 'explicit' });
|
||||
chain
|
||||
.connect(dry)
|
||||
.connect(dryDelay, delayNode)
|
||||
.connectOne(1, wetDelay) // connect delayNode -> wetDelay
|
||||
.connect(sum);
|
||||
chain.audioNodes.push(delayNode.feedbackGain, delayNode.delayGain);
|
||||
fxNodes['delay'] = [delayNode];
|
||||
fxNodes['delay_mix'] = [wetDelay];
|
||||
}
|
||||
// reverb
|
||||
if (fx.room > 0) {
|
||||
let roomIR;
|
||||
if (fx.ir !== undefined) {
|
||||
let url;
|
||||
let sample = getSound(fx.ir);
|
||||
if (Array.isArray(sample)) {
|
||||
url = sample.data.samples[fx.i % sample.data.samples.length];
|
||||
} else if (typeof sample === 'object') {
|
||||
url = Object.values(sample.data.samples).flat()[fx.i % Object.values(sample.data.samples).length];
|
||||
}
|
||||
roomIR = await loadBuffer(url, ac, fx.ir, 0);
|
||||
}
|
||||
const dry = gainNode(1);
|
||||
const reverbNode = ac.createReverb(
|
||||
fx.roomsize,
|
||||
fx.roomfade,
|
||||
fx.roomlp,
|
||||
fx.roomdim,
|
||||
roomIR,
|
||||
fx.irspeed,
|
||||
fx.irbegin,
|
||||
);
|
||||
const wetReverb = gainNode(fx.room);
|
||||
const dryReverb = gainNode(fx.dry ?? 1);
|
||||
const sum = new GainNode(ac, { gain: 1, channelCount: 2, channelCountMode: 'explicit' });
|
||||
chain
|
||||
.connect(dry)
|
||||
.connect(dryReverb, reverbNode)
|
||||
.connectOne(1, wetReverb) // connect reverbNode -> wetReverb
|
||||
.connect(sum);
|
||||
fxNodes['room'] = [reverbNode];
|
||||
fxNodes['room_mix'] = [wetReverb];
|
||||
}
|
||||
}
|
||||
|
||||
if (value.hcutoff !== undefined) {
|
||||
const hpMap = {
|
||||
frequency: 'hcutoff',
|
||||
q: 'hresonance',
|
||||
attack: 'hpattack',
|
||||
decay: 'hpdecay',
|
||||
sustain: 'hpsustain',
|
||||
release: 'hprelease',
|
||||
env: 'hpenv',
|
||||
anchor: 'fanchor',
|
||||
model: 'ftype',
|
||||
drive: 'drive',
|
||||
rate: 'hprate',
|
||||
sync: 'hpsync',
|
||||
depth: 'hpdepth',
|
||||
depthfrequency: 'hpdepthfrequency',
|
||||
shape: 'hpshape',
|
||||
dcoffset: 'hpdc',
|
||||
skew: 'hpskew',
|
||||
};
|
||||
const hpParams = pickAndRename(value, hpMap);
|
||||
hpParams.type = 'highpass';
|
||||
const { filter: hpf1, lfo: lfo1 } = filt(hpParams);
|
||||
nodes['hpf'] = [hpf1];
|
||||
nodes['hpf_lfo'] = [lfo1];
|
||||
lfo1 && audioNodes.push(lfo1);
|
||||
chain.push(hpf1);
|
||||
if (ftype === '24db') {
|
||||
const { filter: hpf2, lfo: lfo2 } = filt(hpParams);
|
||||
nodes['hpf'].push(hpf2);
|
||||
nodes['hpf_lfo'].push(lfo2);
|
||||
chain.push(hpf2);
|
||||
lfo2 && audioNodes.push(lfo2);
|
||||
}
|
||||
}
|
||||
|
||||
if (value.bandf !== undefined) {
|
||||
const bpMap = {
|
||||
frequency: 'bandf',
|
||||
q: 'bandq',
|
||||
attack: 'bpattack',
|
||||
decay: 'bpdecay',
|
||||
sustain: 'bpsustain',
|
||||
release: 'bprelease',
|
||||
env: 'bpenv',
|
||||
anchor: 'fanchor',
|
||||
model: 'ftype',
|
||||
drive: 'drive',
|
||||
rate: 'bprate',
|
||||
sync: 'bpsync',
|
||||
depth: 'bpdepth',
|
||||
depthfrequency: 'bpdepthfrequency',
|
||||
shape: 'bpshape',
|
||||
dcoffset: 'bpdc',
|
||||
skew: 'bpskew',
|
||||
};
|
||||
const bpParams = pickAndRename(value, bpMap);
|
||||
bpParams.type = 'bandpass';
|
||||
const { filter: bpf1, lfo: lfo1 } = filt(bpParams);
|
||||
nodes['bpf'] = [bpf1];
|
||||
nodes['bpf_lfo'] = [lfo1];
|
||||
chain.push(bpf1);
|
||||
lfo1 && audioNodes.push(lfo1);
|
||||
if (ftype === '24db') {
|
||||
const { filter: bpf2, lfo: lfo2 } = filt(bpParams);
|
||||
nodes['bpf'].push(bpf2);
|
||||
nodes['bpf_lfo'].push(lfo2);
|
||||
chain.push(bpf2);
|
||||
lfo2 && audioNodes.push(lfo2);
|
||||
}
|
||||
}
|
||||
|
||||
if (vowel !== undefined) {
|
||||
const vowelFilter = ac.createVowelFilter(vowel);
|
||||
nodes['vowel'] = [vowelFilter];
|
||||
chain.push(vowelFilter);
|
||||
}
|
||||
|
||||
// effects
|
||||
if (coarse !== undefined) {
|
||||
const coarseNode = getWorklet(ac, 'coarse-processor', { coarse });
|
||||
nodes['coarse'] = [coarseNode];
|
||||
chain.push(coarseNode);
|
||||
}
|
||||
if (crush !== undefined) {
|
||||
const crushNode = getWorklet(ac, 'crush-processor', { crush });
|
||||
nodes['crush'] = [crushNode];
|
||||
chain.push(crushNode);
|
||||
}
|
||||
if (shape !== undefined) {
|
||||
const shapeNode = getWorklet(ac, 'shape-processor', { shape, postgain: shapevol });
|
||||
nodes['shape'] = [shapeNode];
|
||||
chain.push(shapeNode);
|
||||
}
|
||||
if (distort !== undefined) {
|
||||
const distortNode = getDistortion(distort, distortvol, distorttype);
|
||||
nodes['distort'] = [distortNode];
|
||||
chain.push(distortNode);
|
||||
}
|
||||
|
||||
if (tremolosync != null) {
|
||||
tremolo = cps * tremolosync;
|
||||
}
|
||||
|
||||
if (value.wtPosSynced != null) {
|
||||
value.wtPosRate /= cps;
|
||||
}
|
||||
|
||||
if (value.wtWarpSynced != null) {
|
||||
value.wtWarpRate /= cps;
|
||||
}
|
||||
|
||||
if (tremolo !== undefined) {
|
||||
// Allow clipping of modulator for more dynamic possiblities, and to prevent speaker overload
|
||||
// EX: a triangle waveform will clip like this /-\ when the depth is above 1
|
||||
const gain = Math.max(1 - tremolodepth, 0);
|
||||
const amGain = new GainNode(ac, { gain });
|
||||
|
||||
const time = cycle / cps;
|
||||
const lfo = getLfo(ac, {
|
||||
skew: tremoloskew ?? (tremoloshape != null ? 0.5 : 1),
|
||||
frequency: tremolo,
|
||||
depth: tremolodepth,
|
||||
time,
|
||||
dcoffset: 0,
|
||||
shape: tremoloshape,
|
||||
phaseoffset: tremolophase,
|
||||
min: 0,
|
||||
max: 1,
|
||||
curve: 1.5,
|
||||
begin: t,
|
||||
end: endWithRelease,
|
||||
});
|
||||
nodes['tremolo'] = [lfo];
|
||||
nodes['tremolo_gain'] = [amGain];
|
||||
lfo.connect(amGain.gain);
|
||||
audioNodes.push(lfo);
|
||||
chain.push(amGain);
|
||||
}
|
||||
|
||||
if (compressorThreshold !== undefined) {
|
||||
const compressorNode = getCompressor(
|
||||
ac,
|
||||
compressorThreshold,
|
||||
compressorRatio,
|
||||
compressorKnee,
|
||||
compressorAttack,
|
||||
compressorRelease,
|
||||
);
|
||||
nodes['compressor'] = [compressorNode];
|
||||
chain.push(compressorNode);
|
||||
}
|
||||
|
||||
// panning
|
||||
if (pan !== undefined) {
|
||||
const panner = ac.createStereoPanner();
|
||||
panner.pan.value = 2 * pan - 1;
|
||||
chain.push(panner);
|
||||
}
|
||||
// phaser
|
||||
if (phaserrate !== undefined && phaserdepth > 0) {
|
||||
const { filterChain, lfo } = getPhaser(t, endWithRelease, phaserrate, phaserdepth, phasercenter, phasersweep);
|
||||
nodes['phaser'] = [...filterChain];
|
||||
nodes['phaser_lfo'] = [lfo];
|
||||
chain.push(...filterChain);
|
||||
audioNodes.push(lfo);
|
||||
if (FXrelease !== undefined && FXrelease > release) {
|
||||
const releaseNode = gainNode(1);
|
||||
releaseNode.gain.setValueAtTime(1, end + release);
|
||||
releaseNode.gain.linearRampToValueAtTime(0, endWithRelease);
|
||||
chain.connect(releaseNode);
|
||||
}
|
||||
|
||||
// last gain
|
||||
const post = new GainNode(ac, { gain: postgain });
|
||||
nodes['post'] = [post];
|
||||
chain.push(post);
|
||||
nodes.main['post'] = [post];
|
||||
chain.connect(post);
|
||||
|
||||
// delay
|
||||
if (delay > 0 && delaytime > 0 && delayfeedback > 0) {
|
||||
const delayNode = orbitBus.getDelay(delaytime, delayfeedback, t);
|
||||
nodes['delay'] = [delayNode];
|
||||
nodes.main['delay'] = [delayNode];
|
||||
const delaySend = orbitBus.sendDelay(post, delay);
|
||||
nodes['delay_mix'] = [delaySend];
|
||||
audioNodes.push(delaySend);
|
||||
nodes.main['delay_mix'] = [delaySend];
|
||||
chain.audioNodes.push(delaySend);
|
||||
}
|
||||
// reverb
|
||||
if (room > 0) {
|
||||
@@ -838,81 +913,92 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
|
||||
roomIR = await loadBuffer(url, ac, ir, 0);
|
||||
}
|
||||
const roomNode = orbitBus.getReverb(roomsize, roomfade, roomlp, roomdim, roomIR, irspeed, irbegin);
|
||||
nodes['room'] = [roomNode];
|
||||
nodes.main['room'] = [roomNode];
|
||||
const reverbSend = orbitBus.sendReverb(post, room);
|
||||
nodes['room_mix'] = [reverbSend];
|
||||
audioNodes.push(reverbSend);
|
||||
nodes.main['room_mix'] = [reverbSend];
|
||||
chain.audioNodes.push(reverbSend);
|
||||
}
|
||||
if (bus != null) {
|
||||
const busNode = audioController.getBus(bus);
|
||||
const busSend = effectSend(post, busNode, busgain);
|
||||
audioNodes.push(busSend);
|
||||
chain.audioNodes.push(busSend);
|
||||
}
|
||||
|
||||
if (djf != null) {
|
||||
const djfNode = orbitBus.getDjf(djf, t);
|
||||
nodes['djf'] = [djfNode];
|
||||
nodes.main['djf'] = [djfNode];
|
||||
}
|
||||
|
||||
// analyser
|
||||
if (analyze && !(ac instanceof OfflineAudioContext)) {
|
||||
const analyserNode = getAnalyserById(analyze, 2 ** (fft + 5));
|
||||
const analyserSend = effectSend(post, analyserNode, 1);
|
||||
audioNodes.push(analyserSend);
|
||||
chain.audioNodes.push(analyserSend);
|
||||
}
|
||||
if (dry != null) {
|
||||
dry = applyGainCurve(dry);
|
||||
const dryGain = new GainNode(ac, { gain: dry });
|
||||
chain.push(dryGain);
|
||||
chain.connect(dryGain);
|
||||
orbitBus.connectToOutput(dryGain);
|
||||
} else {
|
||||
orbitBus.connectToOutput(post);
|
||||
}
|
||||
|
||||
// connect chain elements together
|
||||
chain.slice(1).reduce((last, current) => last.connect(current), chain[0]);
|
||||
audioNodes.push(...chain);
|
||||
|
||||
// finally, now that `nodes` is populated, set up modulators
|
||||
if (value.lfo) {
|
||||
for (const id of value.lfo.__ids) {
|
||||
const params = value.lfo[id];
|
||||
const lfo = connectLFO(
|
||||
id,
|
||||
{
|
||||
...params,
|
||||
cps,
|
||||
cycle,
|
||||
begin: t,
|
||||
end: endWithRelease,
|
||||
},
|
||||
nodes,
|
||||
);
|
||||
lfo && audioNodes.push(lfo);
|
||||
FX.forEach((fx, idx) => {
|
||||
const key = idx === FX.length - 1 ? 'main' : idx;
|
||||
if (fx.lfo) {
|
||||
for (const id of fx.lfo.__ids) {
|
||||
const params = fx.lfo[id];
|
||||
params.fxi ??= key;
|
||||
const lfo = connectLFO(
|
||||
id,
|
||||
{
|
||||
...params,
|
||||
cps,
|
||||
cycle,
|
||||
begin: t,
|
||||
end: endWithRelease,
|
||||
},
|
||||
nodes,
|
||||
);
|
||||
lfo && chain.audioNodes.push(lfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (value.env) {
|
||||
for (const id of value.env.__ids) {
|
||||
const params = value.env[id];
|
||||
const env = connectEnvelope(
|
||||
id,
|
||||
{
|
||||
...params,
|
||||
begin: t,
|
||||
end: endWithRelease,
|
||||
},
|
||||
nodes,
|
||||
);
|
||||
env && audioNodes.push(env);
|
||||
if (fx.env) {
|
||||
for (const id of fx.env.__ids) {
|
||||
const params = fx.env[id];
|
||||
params.fxi ??= key;
|
||||
const env = connectEnvelope(
|
||||
id,
|
||||
{
|
||||
...params,
|
||||
begin: t,
|
||||
end: endWithRelease,
|
||||
},
|
||||
nodes,
|
||||
);
|
||||
env && chain.audioNodes.push(env);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (value.bmod) {
|
||||
for (const id of value.bmod.__ids) {
|
||||
const params = value.bmod[id];
|
||||
const { toCleanup } = connectBusModulator({ ...params, begin: t, end: endWithRelease }, nodes, controller);
|
||||
audioNodes.push(...toCleanup);
|
||||
if (fx.bmod) {
|
||||
for (const id of fx.bmod.__ids) {
|
||||
const params = fx.bmod[id];
|
||||
params.fxi ??= key;
|
||||
const { toCleanup } = connectBusModulator({ ...params, begin: t, end: endWithRelease }, nodes, controller);
|
||||
chain.audioNodes.push(...toCleanup);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
webAudioTimeout(
|
||||
ac,
|
||||
() => {
|
||||
chain.releaseNodes();
|
||||
activeSoundSources.delete(chainID);
|
||||
},
|
||||
0,
|
||||
endWithRelease,
|
||||
);
|
||||
};
|
||||
|
||||
export const superdoughTrigger = (t, hap, ct, cps) => {
|
||||
|
||||
Reference in New Issue
Block a user