Skip to content

Diode Filter

The DiodeFilter component is a nonlinear ladder-style filter implemented in an AudioWorklet. It provides cutoff, resonance, and drive, plus CV modulation of cutoff.

Props

PropTypeDefaultDescription
inputModStreamRefRequiredAudio signal to filter
outputModStreamRefRequiredFiltered audio output
labelstring'diode-filter'Label for the component in metadata
cutoffnumber1000Cutoff frequency in Hz (controlled or initial value)
onCutoffChange(cutoff: number) => void-Callback when cutoff changes
resonancenumber0.1Resonance amount (controlled or initial value)
onResonanceChange(resonance: number) => void-Callback when resonance changes
drivenumber0.0Input drive / saturation amount
onDriveChange(drive: number) => void-Callback when drive changes
enabledbooleantrueEnables/bypasses processing (true bypass)
onEnabledChange(enabled: boolean) => void-Callback when enabled changes
cvModStreamRef-Optional CV input for cutoff modulation
cvAmountnumber1000Amount of CV modulation in Hz
onCvAmountChange(cvAmount: number) => void-Callback when cvAmount changes
childrenfunction-Render prop function receiving control props

Render Props

PropertyTypeDescription
cutoffnumberCurrent cutoff in Hz
setCutoff(value: number) => voidUpdate cutoff
resonancenumberCurrent resonance
setResonance(value: number) => voidUpdate resonance
drivenumberCurrent drive
setDrive(value: number) => voidUpdate drive
cvAmountnumberCurrent CV amount
setCvAmount(value: number) => voidUpdate CV amount
enabledbooleanWhether processing is enabled
setEnabled(value: boolean) => voidToggle enabled state
isActivebooleanWhether the node is active

Usage

Basic Usage

tsx
import { ToneGenerator, DiodeFilter, Monitor } from '@mode-7/mod';
import { useRef } from 'react';

function App() {
  const toneOut = useRef(null);
  const filterOut = useRef(null);

  return (
    <>
      <ToneGenerator output={toneOut} waveform="sawtooth" />
      <DiodeFilter input={toneOut} output={filterOut} cutoff={900} resonance={0.7} drive={0.5} />
      <Monitor input={filterOut} />
    </>
  );
}

With CV Modulation

tsx
import { LFO, DiodeFilter, ToneGenerator, Monitor } from '@mode-7/mod';
import { useRef } from 'react';

function App() {
  const toneOut = useRef(null);
  const lfoOut = useRef(null);
  const filterOut = useRef(null);

  return (
    <>
      <ToneGenerator output={toneOut} waveform="sawtooth" />
      <LFO output={lfoOut} frequency={0.5} amplitude={1.0} />
      <DiodeFilter input={toneOut} output={filterOut} cv={lfoOut} cvAmount={1200} />
      <Monitor input={filterOut} />
    </>
  );
}

Notes

  • The filter runs in an AudioWorklet for consistent audio-thread timing.
  • enabled={false} bypasses the worklet and passes input directly to output.
  • Filter - Biquad filter alternative
  • LFO - CV modulation source

Released under the MIT License.