Table of Contents

Class AudioEffect

Namespace
NAudio.Effects
Assembly
NAudio.Core.dll

Base class for effects. Provides click-free Bypass and dry/wet Mix for free: it captures the dry signal, calls ProcessBlock(Span<float>) to produce the wet signal in place, then blends them with a smoothed mix coefficient so toggling bypass or moving the mix never clicks. Derived effects implement OnConfigure(WaveFormat) and ProcessBlock(Span<float>).

public abstract class AudioEffect : IAudioEffect
Inheritance
AudioEffect
Implements
Derived
Inherited Members

Remarks

While fully bypassed the effect is still run (its output is discarded) so its internal state stays warm and un-bypassing does not click. The dry copy and the per-sample blend are skipped on the common fully-wet, settled path.

Properties

Bypass

When true the effect is bypassed (output equals input). The transition is ramped, so toggling this while audio flows does not click.

public bool Bypass { get; set; }

Property Value

bool

Channels

Channel count from the configured format.

protected int Channels { get; }

Property Value

int

LatencySamples

Processing latency the effect introduces, in samples per channel. Zero for effects with no inherent delay; non-zero for look-ahead or block/partitioned designs that need delay compensation in a chain.

public virtual int LatencySamples { get; }

Property Value

int

Mix

Dry/wet mix: 0 = fully dry (effect inaudible), 1 = fully wet. Changes are ramped, so moving this while audio flows does not click. Note: for effects that report a non-zero LatencySamples (e.g. pitch shift, convolution), the captured dry signal is not delay-compensated, so a partial mix blends the dry against the latency-delayed wet signal.

public float Mix { get; set; }

Property Value

float

SampleRate

Sample rate from the configured format.

protected int SampleRate { get; }

Property Value

int

WaveFormat

The format the effect was configured with, or null before Configure(WaveFormat) has been called.

protected WaveFormat WaveFormat { get; }

Property Value

WaveFormat

Methods

Configure(WaveFormat)

Supplies the sample rate and channel count the effect will process. Called before the first Process(Span<float>), and again if the format changes.

public void Configure(WaveFormat format)

Parameters

format WaveFormat

OnConfigure(WaveFormat)

Called by Configure(WaveFormat) after the format is stored. Derived effects allocate and size their sample-rate-dependent state here.

protected abstract void OnConfigure(WaveFormat format)

Parameters

format WaveFormat

Process(Span<float>)

Processes one block of interleaved samples in place.

public void Process(Span<float> buffer)

Parameters

buffer Span<float>

Interleaved samples to transform in place.

ProcessBlock(Span<float>)

Transforms buffer in place into the fully-wet signal. The base class handles dry/wet mixing and bypass around this call.

protected abstract void ProcessBlock(Span<float> buffer)

Parameters

buffer Span<float>

Reset()

Clears internal state (delay lines, envelopes, smoothers) so the next block starts as if from silence.

public virtual void Reset()