Table of Contents

Class EffectChain

Namespace
NAudio.Effects
Assembly
NAudio.Core.dll

An ordered chain of IAudioEffects exposed as a single ISampleProvider. Effects are applied in the order they were added.

public sealed class EffectChain : ISampleProvider
Inheritance
EffectChain
Implements
Inherited Members
Extension Methods

Remarks

The chain may be edited (Add(IAudioEffect), Insert(int, IAudioEffect), RemoveAt(int), Move(int, int)) from one thread while another thread calls Read(Span<float>): each edit publishes a new immutable array with a single atomic write, so a concurrent Read(Span<float>) always sees either the pre- or post-edit chain, never a partial state, and never takes a lock. Edits are serialized against each other by an internal lock, so multiple editor threads are also safe. New effects are configured for the source format on the editing thread before they are published, so configuration never lands on the audio thread.

Constructors

EffectChain(ISampleProvider)

Creates a chain that reads from source.

public EffectChain(ISampleProvider source)

Parameters

source ISampleProvider

Properties

Effects

A point-in-time snapshot of the effects in the chain, in processing order. Does not reflect edits made after it is read.

public IReadOnlyList<IAudioEffect> Effects { get; }

Property Value

IReadOnlyList<IAudioEffect>

LatencySamples

Total added latency of the chain, in samples per channel.

public int LatencySamples { get; }

Property Value

int

WaveFormat

Gets the WaveFormat of this Sample Provider.

public WaveFormat WaveFormat { get; }

Property Value

WaveFormat

The wave format.

Methods

Add(IAudioEffect)

Appends an effect to the end of the chain, configuring it with the source format, and returns this chain so calls can be fluently chained.

public EffectChain Add(IAudioEffect effect)

Parameters

effect IAudioEffect

Returns

EffectChain

Insert(int, IAudioEffect)

Inserts an effect at index, configuring it with the source format. Existing effects keep their state (they are not reconfigured).

public void Insert(int index, IAudioEffect effect)

Parameters

index int
effect IAudioEffect

Move(int, int)

Moves the effect at oldIndex to newIndex, reordering the chain without reconfiguring or resetting any effect.

public void Move(int oldIndex, int newIndex)

Parameters

oldIndex int
newIndex int

Read(Span<float>)

Fill the specified buffer with 32 bit floating point samples

public int Read(Span<float> buffer)

Parameters

buffer Span<float>

The buffer to fill with samples.

Returns

int

The number of samples written. Return 0 to signal end of stream.

RemoveAt(int)

Removes the effect at index from the chain. The removed effect simply stops being processed; its own state is left untouched.

public void RemoveAt(int index)

Parameters

index int

Reset()

Resets every effect in the chain, clearing their internal state (delay lines, filter history, reverb tails) without changing the chain or its configuration. Use when reusing the chain on a new signal, e.g. after seeking the source.

public void Reset()