Skip to content

Limiter ​

Limits audio peaks to prevent clipping and maintain consistent output levels, essential for mastering and preventing distortion.

Props ​

PropTypeDefaultDescription
inputModStreamRefRequiredReference to input audio signal
outputModStreamRefRequiredReference to output audio signal
labelstring'limiter'Label for metadata
thresholdnumber-1Threshold in dB (controlled or initial value)
onThresholdChange(value: number) => void-Callback when threshold changes
releasenumber0.05Release time in seconds (controlled or initial value)
onReleaseChange(value: number) => void-Callback when release changes
enabledbooleantrueWhether the component is enabled or bypassed
onEnabledChange(enabled: boolean) => void-Callback when enabled state changes
childrenfunction-Render prop function

Render Props ​

When using the children render prop, the following controls are provided:

PropertyTypeDescription
thresholdnumberCurrent threshold in dB
setThreshold(value: number) => voidUpdate the threshold
releasenumberCurrent release time in seconds
setRelease(value: number) => voidUpdate the release time
enabledbooleanWhether the component is enabled
setEnabled(value: boolean) => voidToggle enabled/bypass state
isActivebooleanWhether the processor is active

Usage ​

Basic Usage ​

tsx
import { Limiter } from '@mode-7/mod';

function MyComponent() {
  const inputRef = useRef<ModStreamRef>(null);
  const outputRef = useRef<ModStreamRef>(null);

  return (
    <Limiter
      input={inputRef}
      output={outputRef}
      threshold={-1}
      release={0.05}
    />
  );
}

With Render Props ​

tsx
import { Limiter } from '@mode-7/mod';

function MyComponent() {
  const inputRef = useRef<ModStreamRef>(null);
  const outputRef = useRef<ModStreamRef>(null);

  return (
    <Limiter input={inputRef} output={outputRef}>
      {({ threshold, setThreshold, release, setRelease }) => (
        <div>
          <label>
            Threshold: {threshold.toFixed(1)} dB
            <input
              type="range"
              min="-20"
              max="0"
              step="0.1"
              value={threshold}
              onChange={(e) => setThreshold(parseFloat(e.target.value))}
            />
          </label>
          <label>
            Release: {(release * 1000).toFixed(0)} ms
            <input
              type="range"
              min="0.01"
              max="0.5"
              step="0.01"
              value={release}
              onChange={(e) => setRelease(parseFloat(e.target.value))}
            />
          </label>
        </div>
      )}
    </Limiter>
  );
}

Controlled Props ​

tsx
import { Limiter } from '@mode-7/mod';
import { useState } from 'react';

function MyComponent() {
  const inputRef = useRef<ModStreamRef>(null);
  const outputRef = useRef<ModStreamRef>(null);
  const [threshold, setThreshold] = useState(-1);
  const [release, setRelease] = useState(0.05);

  return (
    <div>
      <Limiter
        input={inputRef}
        output={outputRef}
        threshold={threshold}
        onThresholdChange={setThreshold}
        release={release}
        onReleaseChange={setRelease}
      />
      <button onClick={() => setThreshold(-3)}>Conservative</button>
      <button onClick={() => setThreshold(-1)}>Aggressive</button>
      <button onClick={() => setRelease(0.01)}>Fast</button>
      <button onClick={() => setRelease(0.2)}>Slow</button>
    </div>
  );
}

Imperative Refs ​

tsx
import { Limiter } from '@mode-7/mod';
import { useRef } from 'react';

function MyComponent() {
  const inputRef = useRef<ModStreamRef>(null);
  const outputRef = useRef<ModStreamRef>(null);
  const limiterRef = useRef(null);

  const logState = () => {
    if (limiterRef.current) {
      const state = limiterRef.current.getState();
      console.log('Limiter state:', state);
    }
  };

  return (
    <div>
      <Limiter
        ref={limiterRef}
        input={inputRef}
        output={outputRef}
      />
      <button onClick={logState}>Log State</button>
    </div>
  );
}

Note: The imperative handle provides read-only access via getState(). To control the component programmatically, use the controlled props pattern shown above.

Bypass/Enable ​

The enabled prop allows you to bypass the component's processing. When enabled is false, the audio passes through directly without any processing, saving CPU resources. This implements a true bypass.

Usage ​

tsx
import { Limiter } from '@mode-7/mod';
import { useState } from 'react';

function App() {
  const [enabled, setEnabled] = useState(true);

  return (
    <Limiter
      input={input}
      output={output}
      enabled={enabled}
      onEnabledChange={setEnabled}
    />
  );
}

With Render Props ​

tsx
<Limiter input={input} output={output}>
  {({ enabled, setEnabled, threshold, setThreshold, release, setRelease }) => (
    <div>
      <button onClick={() => setEnabled(!enabled)}>
        {enabled ? 'Bypass' : 'Enable'}
      </button>
      {/* Other controls */}
    </div>
  )}
</Limiter>

Important Notes ​

  • The limiter prevents audio from exceeding the threshold level
  • Threshold is typically set close to 0 dB to prevent clipping (e.g., -1 to -3 dB)
  • Lower threshold values provide more aggressive limiting
  • Fast release times (10-50ms) are transparent but may cause pumping on bass-heavy material
  • Slower release times (100-500ms) are smoother but may reduce dynamic range
  • Limiters are typically placed at the end of an effects chain
  • Use for: preventing clipping, maximizing loudness, protecting speakers/headphones
  • Compressor - Dynamic range compression with ratio control
  • Gate - Silences audio below a threshold
  • Distortion - Adds harmonic distortion

Released under the MIT License.