Class EffectChain
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
sourceISampleProvider
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
LatencySamples
Total added latency of the chain, in samples per channel.
public int LatencySamples { get; }
Property Value
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
effectIAudioEffect
Returns
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
indexinteffectIAudioEffect
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
Read(Span<float>)
Fill the specified buffer with 32 bit floating point samples
public int Read(Span<float> buffer)
Parameters
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
indexint
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()