fix: filter envelopes + simplify

This commit is contained in:
Felix Roos 2023-09-08 01:40:10 +02:00
parent e597b6473d
commit e2711ba911
2 changed files with 23 additions and 28 deletions

View File

@ -66,15 +66,15 @@ export const getADSR = (attack, decay, sustain, release, velocity, begin, end) =
return gainNode; return gainNode;
}; };
export const getParamADSR = (param, attack, decay, sustain, release, velocity, begin, end) => { export const getParamADSR = (param, attack, decay, sustain, release, max, begin, end) => {
param.setValueAtTime(0, begin); param.setValueAtTime(0, begin);
param.linearRampToValueAtTime(velocity, begin + attack); param.linearRampToValueAtTime(max, begin + attack);
param.linearRampToValueAtTime(sustain * velocity, begin + attack + decay); param.linearRampToValueAtTime(sustain * max, begin + attack + decay);
param.setValueAtTime(sustain * velocity, end); param.setValueAtTime(sustain * max, end);
param.linearRampToValueAtTime(0, end + release - 0.1); param.linearRampToValueAtTime(0, end + release);
}; };
export function createFilter(context, type, frequency, Q, attack, decay, sustain, release, fenv, t) { export function createFilter(context, type, frequency, Q, attack, decay, sustain, release, fenv, start, end) {
const filter = context.createBiquadFilter(); const filter = context.createBiquadFilter();
filter.type = type; filter.type = type;
filter.frequency.value = frequency; filter.frequency.value = frequency;
@ -89,8 +89,8 @@ export function createFilter(context, type, frequency, Q, attack, decay, sustain
sustain, sustain,
release, release,
frequency * fenv > 22000 ? 22000 : frequency * fenv, frequency * fenv > 22000 ? 22000 : frequency * fenv,
t, start,
t + attack + decay + release, end + release,
); );
return filter; return filter;
} }

View File

@ -201,10 +201,6 @@ export const superdough = async (value, deadline, hapDuration) => {
bpsustain = 0.6, bpsustain = 0.6,
bprelease = 0.01, bprelease = 0.01,
bandq = 1, bandq = 1,
// full adsr for filter
lpadsr,
hpadsr,
bpadsr,
// //
coarse, coarse,
crush, crush,
@ -229,9 +225,6 @@ export const superdough = async (value, deadline, hapDuration) => {
if (bank && s) { if (bank && s) {
s = `${bank}_${s}`; s = `${bank}_${s}`;
} }
lpadsr && (lpattack = lpadsr[0]) && (lpdecay = lpadsr[1]) && (lpsustain = lpadsr[2]) && (lprelease = lpadsr[3]);
hpadsr && (hpattack = hpadsr[0]) && (hpdecay = hpadsr[1]) && (hpsustain = hpadsr[2]) && (hprelease = hpadsr[3]);
bpadsr && (bpattack = bpadsr[0]) && (bpdecay = bpadsr[1]) && (bpsustain = bpadsr[2]) && (bprelease = bpadsr[3]);
// get source AudioNode // get source AudioNode
let sourceNode; let sourceNode;
if (source) { if (source) {
@ -262,19 +255,18 @@ export const superdough = async (value, deadline, hapDuration) => {
chain.push(gainNode(gain)); chain.push(gainNode(gain));
if (cutoff !== undefined) { if (cutoff !== undefined) {
const filter1 = createFilter(ac, 'lowpass', cutoff, resonance, lpattack, lpdecay, lpsustain, lprelease, fenv, t); console.log('lpattack', lpattack);
chain.push(filter1); let lp = () =>
createFilter(ac, 'lowpass', cutoff, resonance, lpattack, lpdecay, lpsustain, lprelease, fenv, t, t + hapDuration);
chain.push(lp());
if (order === '24db') { if (order === '24db') {
const filter2 = createFilter(ac, 'lowpass', cutoff, resonance, lpattack, lpdecay, lpsustain, lprelease, fenv, t); chain.push(lp());
chain.push(filter2);
} }
} }
if (hcutoff !== undefined) { if (hcutoff !== undefined) {
const filter1 = createFilter(ac, 'highpass', hcutoff, hresonance, hpattack, hpdecay, hpsustain, hprelease, fenv, t); let hp = () =>
chain.push(filter1); createFilter(
if (order === '24db') {
const filter2 = createFilter(
ac, ac,
'highpass', 'highpass',
hcutoff, hcutoff,
@ -285,17 +277,20 @@ export const superdough = async (value, deadline, hapDuration) => {
hprelease, hprelease,
fenv, fenv,
t, t,
t + hapDuration,
); );
chain.push(filter2); chain.push(hp());
if (order === '24db') {
chain.push(hp());
} }
} }
if (bandf !== undefined) { if (bandf !== undefined) {
const filter1 = createFilter(ac, 'bandpass', bandf, bandq, bpattack, bpdecay, bpsustain, bprelease, fenv, t); let bp = () =>
chain.push(filter1); createFilter(ac, 'bandpass', bandf, bandq, bpattack, bpdecay, bpsustain, bprelease, fenv, t, t + hapDuration);
chain.push(bp());
if (order === '24db') { if (order === '24db') {
const filter2 = createFilter(ac, 'bandpass', bandf, bandq, bpattack, bpdecay, bpsustain, bprelease, fenv, t); chain.push(bp());
chain.push(filter2);
} }
} }