fully implemented

This commit is contained in:
Jade (Rose) Rowland 2025-07-08 00:26:15 -04:00
parent d9e44dcda6
commit ce5f425142
7 changed files with 227 additions and 306 deletions

View file

@ -45,8 +45,6 @@ export function setGainCurve(newGainCurveFunc) {
gainCurveFunc = newGainCurveFunc;
}
function aliasBankMap(aliasMap) {
// Make all bank keys lower case for case insensitivity
for (const key in aliasMap) {
@ -328,22 +326,26 @@ function getDelay(orbit, delaytime, delayfeedback, t, channels) {
}
export function getLfo(audioContext, begin, end, properties = {}) {
const { dcoffset = -0.5, depth = 1 } = properties;
return getWorklet(audioContext, 'lfo-processor', {
frequency: 1,
depth: 1,
depth,
skew: 0,
phaseoffset: 0,
time: begin,
begin,
end,
shape: 1,
dcoffset: -0.5,
dcoffset,
min: dcoffset - depth * 0.5,
max: dcoffset + depth * 0.5,
curve: 1,
...properties,
});
}
export function getSyncedLfo(audioContext, time, end, cps, cycle, properties = {}) {
const frequency = cycle/cps
const frequency = cycle / cps;
return getWorklet(audioContext, 'lfo-processor', {
frequency,
@ -499,10 +501,11 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle) => {
// destructure
let {
am,
amsync,
amdepth = 1,
amskew = 0.5,
amskew = 1,
amphase = 0,
amshape = 1,
amshape = 0,
s = getDefaultValue('s'),
bank,
source,
@ -512,6 +515,7 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle) => {
// filters
fanchor = getDefaultValue('fanchor'),
drive = 0.69,
release = 0,
// low pass
cutoff,
lpenv,
@ -587,8 +591,11 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle) => {
distortvol = applyGainCurve(distortvol);
delay = applyGainCurve(delay);
velocity = applyGainCurve(velocity);
amdepth = applyGainCurve(amdepth);
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 chainID = Math.round(Math.random() * 1000000);
// oldest audio nodes will be destroyed if maximum polyphony is exceeded
@ -663,7 +670,7 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle) => {
lprelease,
lpenv,
t,
t + hapDuration,
end,
fanchor,
ftype,
drive,
@ -687,7 +694,7 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle) => {
hprelease,
hpenv,
t,
t + hapDuration,
end,
fanchor,
);
chain.push(hp());
@ -698,20 +705,7 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle) => {
if (bandf !== undefined) {
let bp = () =>
createFilter(
ac,
'bandpass',
bandf,
bandq,
bpattack,
bpdecay,
bpsustain,
bprelease,
bpenv,
t,
t + hapDuration,
fanchor,
);
createFilter(ac, 'bandpass', bandf, bandq, bpattack, bpdecay, bpsustain, bprelease, bpenv, t, end, fanchor);
chain.push(bp());
if (ftype === '24db') {
chain.push(bp());
@ -727,45 +721,32 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle) => {
coarse !== undefined && chain.push(getWorklet(ac, 'coarse-processor', { coarse }));
crush !== undefined && chain.push(getWorklet(ac, 'crush-processor', { crush }));
shape !== undefined && chain.push(getWorklet(ac, 'shape-processor', { shape, postgain: shapevol }));
// distort !== undefined && chain.push(getWorklet(ac, 'distort-processor', { distort, postgain: distortvol }));
// am !== undefined &&
// chain.push(
// getWorklet(ac, 'am-processor', {
// speed: am,
// begin: t,
// depth: amdepth,
// skew: amskew,
// phaseoffset: amphase,
// // shape: amshape,
// cps,
// cycle,
// }),
// );
distort !== undefined && chain.push(getWorklet(ac, 'distort-processor', { distort, postgain: distortvol }));
if (amsync != null) {
am = cps / amsync;
}
if (am !== undefined) {
const amGain = new GainNode(ac, { gain: 1 });
const frequency = cps / am
const phaseoffset = cycleToSeconds(amphase, cps)
// 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 - amdepth, 0);
const amGain = new GainNode(ac, { gain });
const time = cycle / cps
// console.info(cycle, time, frequency)
const lfo = getLfo(ac, t, t + hapDuration, {
skew: amskew,
frequency,
const time = cycle / cps;
const lfo = getLfo(ac, t, endWithRelease, {
skew: amskew,
frequency: am,
depth: amdepth,
time,
// dcoffset: 0,
shape: amshape,
phaseoffset
})
lfo.connect(amGain.gain)
chain.push(amGain)
dcoffset: 0,
shape: amshape,
phaseoffset: amphase,
min: 0,
max: 1,
curve: 1.5,
});
lfo.connect(amGain.gain);
chain.push(amGain);
}
compressorThreshold !== undefined &&
@ -781,7 +762,7 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle) => {
}
// phaser
if (phaser !== undefined && phaserdepth > 0) {
const phaserFX = getPhaser(t, t + hapDuration, phaser, phaserdepth, phasercenter, phasersweep);
const phaserFX = getPhaser(t, endWithRelease, phaser, phaserdepth, phasercenter, phasersweep);
chain.push(phaserFX);
}

View file

@ -93,7 +93,10 @@ class LFOProcessor extends AudioWorkletProcessor {
{ name: 'depth', defaultValue: 1 },
{ name: 'phaseoffset', defaultValue: 0 },
{ name: 'shape', defaultValue: 0 },
{ name: 'curve', defaultValue: 1 },
{ name: 'dcoffset', defaultValue: 0 },
{ name: 'min', defaultValue: 0 },
{ name: 'max', defaultValue: 1 },
];
}
@ -110,7 +113,7 @@ class LFOProcessor extends AudioWorkletProcessor {
}
process(inputs, outputs, parameters) {
const begin = parameters['begin'][0]
const begin = parameters['begin'][0];
// eslint-disable-next-line no-undef
if (currentTime >= parameters.end[0]) {
return false;
@ -126,6 +129,9 @@ class LFOProcessor extends AudioWorkletProcessor {
const depth = parameters['depth'][0];
const skew = parameters['skew'][0];
const phaseoffset = parameters['phaseoffset'][0];
const min = parameters['min'][0];
const max = parameters['max'][0];
const curve = parameters['curve'][0];
const dcoffset = parameters['dcoffset'][0];
const shape = waveShapeNames[parameters['shape'][0]];
@ -140,7 +146,7 @@ class LFOProcessor extends AudioWorkletProcessor {
for (let n = 0; n < blockSize; n++) {
for (let i = 0; i < output.length; i++) {
const modval = (waveshapes[shape](this.phase, skew) + dcoffset) * depth;
output[i][n] = modval;
output[i][n] = clamp(Math.pow(modval, curve), min, max);
}
this.incrementPhase(dt);
}
@ -164,8 +170,6 @@ class CoarseProcessor extends AudioWorkletProcessor {
const input = inputs[0];
const output = outputs[0];
const hasInput = !(input[0] === undefined);
if (this.started && !hasInput) {
return false;
@ -901,70 +905,3 @@ class ByteBeatProcessor extends AudioWorkletProcessor {
}
registerProcessor('byte-beat-processor', ByteBeatProcessor);
class AMProcessor extends AudioWorkletProcessor {
static get parameterDescriptors() {
return [
{ name: 'begin', defaultValue: 0 },
{ name: 'cps', defaultValue: 0.5 },
{ name: 'speed', defaultValue: 0.5 },
{ name: 'cycle', defaultValue: 0 },
{ name: 'skew', defaultValue: 0.5 },
{ name: 'depth', defaultValue: 1 },
{ name: 'phaseoffset', defaultValue: 0 },
];
}
constructor() {
super();
this.phase;
this.started = false;
}
incrementPhase(dt) {
this.phase += dt;
if (this.phase > 1.0) {
this.phase = this.phase - 1;
}
}
process(inputs, outputs, parameters) {
const input = inputs[0];
const output = outputs[0];
const hasInput = !(input[0] === undefined);
if (this.started && !hasInput) {
return false;
}
this.started = hasInput;
if (currentTime <= parameters.begin[0]) {
return true;
}
const speed = parameters['speed'][0];
const cps = parameters['cps'][0];
const cycle = parameters['cycle'][0];
const depth = parameters['depth'][0];
const skew = parameters['skew'][0];
const phaseoffset = parameters['phaseoffset'][0];
const frequency = cps / speed
if (this.phase == null) {
const secondsPassed = cycle / cps;
this.phase = _mod(secondsPassed * frequency + phaseoffset, 1);
}
// eslint-disable-next-line no-undef
const dt = frequency / sampleRate;
for (let n = 0; n < blockSize; n++) {
for (let i = 0; i < input.length; i++) {
const modval = clamp(waveshapes.tri(this.phase, skew) * depth + (1 - depth), 0, 1);
output[i][n] = input[i][n] * modval;
}
this.incrementPhase(dt);
}
return true;
}
}
registerProcessor('am-processor', AMProcessor);