diff --git a/packages/superdough/helpers.mjs b/packages/superdough/helpers.mjs index c7883bdb..e51156fe 100644 --- a/packages/superdough/helpers.mjs +++ b/packages/superdough/helpers.mjs @@ -14,6 +14,15 @@ const getSlope = (y1, y2, x1, x2) => { } return (y2 - y1) / (x2 - x1); }; + +export function getWorklet(ac, processor, params, config) { + const node = new AudioWorkletNode(ac, processor, config); + Object.entries(params).forEach(([key, value]) => { + node.parameters.get(key).value = value; + }); + return node; +} + export const getParamADSR = ( param, attack, diff --git a/packages/superdough/superdough.mjs b/packages/superdough/superdough.mjs index fe536d7a..b0e29083 100644 --- a/packages/superdough/superdough.mjs +++ b/packages/superdough/superdough.mjs @@ -9,7 +9,7 @@ import './reverb.mjs'; import './vowel.mjs'; import { clamp, nanFallback } from './util.mjs'; import workletsUrl from './worklets.mjs?url'; -import { createFilter, gainNode, getCompressor } from './helpers.mjs'; +import { createFilter, gainNode, getCompressor, getWorklet } from './helpers.mjs'; import { map } from 'nanostores'; import { logger } from './logger.mjs'; import { loadBuffer } from './sampler.mjs'; @@ -50,14 +50,6 @@ function loadWorklets() { return workletsLoading; } -export function getWorklet(ac, processor, params, config) { - const node = new AudioWorkletNode(ac, processor, config); - Object.entries(params).forEach(([key, value]) => { - node.parameters.get(key).value = value; - }); - return node; -} - // this function should be called on first user interaction (to avoid console warning) export async function initAudio(options = {}) { const { disableWorklets = false } = options; diff --git a/packages/superdough/synth.mjs b/packages/superdough/synth.mjs index 55ecc83f..621a6e59 100644 --- a/packages/superdough/synth.mjs +++ b/packages/superdough/synth.mjs @@ -1,5 +1,5 @@ import { clamp, midiToFreq, noteToMidi } from './util.mjs'; -import { registerSound, getAudioContext, getWorklet } from './superdough.mjs'; +import { registerSound, getAudioContext } from './superdough.mjs'; import { applyFM, gainNode, @@ -8,6 +8,7 @@ import { getPitchEnvelope, getVibratoOscillator, webAudioTimeout, + getWorklet, } from './helpers.mjs'; import { getNoiseMix, getNoiseOscillator } from './noise.mjs'; diff --git a/packages/superdough/worklets.mjs b/packages/superdough/worklets.mjs index fe42b90f..69cb7a59 100644 --- a/packages/superdough/worklets.mjs +++ b/packages/superdough/worklets.mjs @@ -146,7 +146,9 @@ class LadderProcessor extends AudioWorkletProcessor { const resonance = parameters.q[0]; const drive = clamp(Math.exp(parameters.drive[0]), 0.1, 2000); + let cutoff = parameters.frequency[0]; + // eslint-disable-next-line no-undef cutoff = (cutoff * 2 * _PI) / sampleRate; cutoff = cutoff > 1 ? 1 : cutoff;