Skip to content

Commit

Permalink
added lowpass filter lfo
Browse files Browse the repository at this point in the history
  • Loading branch information
thckr committed Jan 18, 2025
1 parent f61916f commit 2c880e2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
13 changes: 13 additions & 0 deletions packages/core/controls.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,19 @@ export const { cut } = registerControl('cut');
*/
export const { cutoff, ctf, lpf, lp } = registerControl(['cutoff', 'resonance', 'lpenv'], 'ctf', 'lpf', 'lp');

/**
* Sets the lowpass filter lfo modulation depth.
* @name lplfo
* @param {number | Pattern} modulation depth of the lowpass filter lfo between 0 and _n_
* @example
* note("c2 e2 f2 g2")
* .sound('sawtooth')
* .lpf(300)
* .lplfo(2)
*/
export const { lplfo } = registerControl('lplfo');


/**
* Sets the lowpass filter envelope modulation depth.
* @name lpenv
Expand Down
13 changes: 9 additions & 4 deletions packages/superdough/helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ export const getADSRValues = (params, curve = 'linear', defaultValues) => {
return [Math.max(a ?? 0, envmin), Math.max(d ?? 0, envmin), Math.min(sustain, envmax), Math.max(r ?? 0, releaseMin)];
};

export function createFilter(context, type, frequency, Q, att, dec, sus, rel, fenv, start, end, fanchor, model, drive) {
export function createFilter(context, type, frequency, Q, att, dec, sus, rel, fenv, start, end, fanchor, model, drive, flfo) {
const curve = 'exponential';
const [attack, decay, sustain, release] = getADSRValues([att, dec, sus, rel], curve, [0.005, 0.14, 0, 0.1]);
let filter;
let frequencyParam;
let frequencyParam,detuneParam;
if (model === 'ladder') {
filter = getWorklet(context, 'ladder-processor', { frequency, q: Q, drive });
frequencyParam = filter.parameters.get('frequency');
Expand All @@ -126,6 +126,7 @@ export function createFilter(context, type, frequency, Q, att, dec, sus, rel, fe
filter.Q.value = Q;
filter.frequency.value = frequency;
frequencyParam = filter.frequency;
detuneParam = filter.detune
}

// envelope is active when any of these values is set
Expand All @@ -140,7 +141,11 @@ export function createFilter(context, type, frequency, Q, att, dec, sus, rel, fe
let max = clamp(2 ** (fenvAbs - offset) * frequency, 0, 20000);
if (fenv < 0) [min, max] = [max, min];
getParamADSR(frequencyParam, attack, decay, sustain, release, min, max, start, end, curve);
return filter;
}
const hasLFO = detuneParam&&flfo !== undefined;
if (hasLFO !== undefined) {
let lfo = getVibratoOscillator(detuneParam, {vib:flfo,vibmod:4}, start);

}
return filter;
}
Expand Down Expand Up @@ -243,7 +248,7 @@ export function applyFM(param, value, begin) {
duration,
} = value;
let modulator;
let stop = () => {};
let stop = () => { };

if (fmModulationIndex) {
const ac = getAudioContext();
Expand Down
2 changes: 2 additions & 0 deletions packages/superdough/superdough.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ export const superdough = async (value, t, hapDuration) => {
lpdecay,
lpsustain,
lprelease,
lplfo,
resonance = getDefaultValue('resonance'),
// high pass
hpenv,
Expand Down Expand Up @@ -475,6 +476,7 @@ export const superdough = async (value, t, hapDuration) => {
fanchor,
ftype,
drive,
lplfo,
);
chain.push(lp());
if (ftype === '24db') {
Expand Down

0 comments on commit 2c880e2

Please sign in to comment.