From e959c275fd6915b9562801e2f04de4143b08cd1a Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Sat, 16 Sep 2023 01:14:14 +0200 Subject: [PATCH] add fanchor --- packages/core/controls.mjs | 1 + packages/superdough/helpers.mjs | 18 +++++++++++++++--- packages/superdough/superdough.mjs | 18 +++++++++++++++++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/packages/core/controls.mjs b/packages/core/controls.mjs index ce52d670..58c4efa1 100644 --- a/packages/core/controls.mjs +++ b/packages/core/controls.mjs @@ -586,6 +586,7 @@ const generic_params = [ */ ['bprelease', 'bpr'], ['ftype'], + ['fanchor'], /** * Applies the cutoff frequency of the **h**igh-**p**ass **f**ilter. * diff --git a/packages/superdough/helpers.mjs b/packages/superdough/helpers.mjs index c15bdb83..92f670d9 100644 --- a/packages/superdough/helpers.mjs +++ b/packages/superdough/helpers.mjs @@ -78,7 +78,20 @@ export const getParamADSR = (param, attack, decay, sustain, release, min, max, b param.linearRampToValueAtTime(min, end + Math.max(release, 0.1)); }; -export function createFilter(context, type, frequency, Q, attack, decay, sustain, release, fenv, start, end) { +export function createFilter( + context, + type, + frequency, + Q, + attack, + decay, + sustain, + release, + fenv, + start, + end, + fanchor = 0.5, +) { const filter = context.createBiquadFilter(); filter.type = type; filter.Q.value = Q; @@ -86,8 +99,7 @@ export function createFilter(context, type, frequency, Q, attack, decay, sustain // Apply ADSR to filter frequency if (fenv !== 0) { - const anchor = 0.5; - const offset = fenv * anchor; + const offset = fenv * fanchor; const min = clamp(2 ** -offset * frequency, 0, 20000); const max = clamp(2 ** (fenv - offset) * frequency, 0, 20000); diff --git a/packages/superdough/superdough.mjs b/packages/superdough/superdough.mjs index 601ab9e0..289e8d97 100644 --- a/packages/superdough/superdough.mjs +++ b/packages/superdough/superdough.mjs @@ -179,6 +179,7 @@ export const superdough = async (value, deadline, hapDuration) => { gain = 0.8, // filters ftype = '12db', + fanchor = 0.5, // low pass cutoff, lpenv, @@ -270,6 +271,7 @@ export const superdough = async (value, deadline, hapDuration) => { lpenv, t, t + hapDuration, + fanchor, ); chain.push(lp()); if (ftype === '24db') { @@ -291,6 +293,7 @@ export const superdough = async (value, deadline, hapDuration) => { hpenv, t, t + hapDuration, + fanchor, ); chain.push(hp()); if (ftype === '24db') { @@ -300,7 +303,20 @@ export const superdough = async (value, deadline, hapDuration) => { if (bandf !== undefined) { let bp = () => - createFilter(ac, 'bandpass', bandf, bandq, bpattack, bpdecay, bpsustain, bprelease, bpenv, t, t + hapDuration); + createFilter( + ac, + 'bandpass', + bandf, + bandq, + bpattack, + bpdecay, + bpsustain, + bprelease, + bpenv, + t, + t + hapDuration, + fanchor, + ); chain.push(bp()); if (ftype === '24db') { chain.push(bp());