Skip to main content

Function: equalizerPresetChain()

function equalizerPresetChain(preset: Pick<EqualizerPreset, "gainsDb">, options?: EqualizerPresetChainOptions): readonly AudioFilter[];

Defined in: packages/player/src/equalizer-presets.ts:468

Turn a preset into a safe, ready-to-apply filter chain.

The chain is:

  1. volume — attenuated by the preset's largest positive gain (plus EqualizerPresetChainOptions.preampDb), so the loudest band comes back to unity rather than above it. A preset that only cuts gets no pre-amp, because it needs none.
  2. One equalizer biquad per non-zero band. Bands sitting at 0 dB are omitted entirely — they would be arithmetic no-ops that still cost a filter instance, so Bass Boost compiles to five bands, not ten.
  3. alimiter — the safety net for the sample peaks the pre-amp's frequency-domain bound cannot catch. On for every non-flat curve, cut-only curves included; opt out with EqualizerPresetChainOptions.limiter, which explains why the default is what it is and what it costs (5 ms of look-ahead; below full scale it changes no sample).

A flat preset compiles to an empty chain: no filters, no cost, no pointless trip through the filter graph.

With EqualizerPresetChainOptions.editable the same three stages come out labelled, and with all ten bands present, so a slider can move one of them through Player.setAudioFilterParam without the chain being rebuilt.

Parameters

ParameterTypeDescription
presetPick<EqualizerPreset, "gainsDb">A built-in from EQUALIZER_PRESETS, a custom one from defineEqualizerPreset, or any { gainsDb } you have to hand.
optionsEqualizerPresetChainOptionsSee EqualizerPresetChainOptions.

Returns

readonly AudioFilter[]

A chain for Player.setAudioFilters.

Example

import { EQUALIZER_PRESETS, equalizerPresetChain } from '@afkcodes/timbre-player'

player.setAudioFilters(equalizerPresetChain(EQUALIZER_PRESETS.rock))
player.setAudioFilters(equalizerPresetChain(EQUALIZER_PRESETS.flat)) // clears