Table of Contents

Class SequencedSampleProvider<T>

Namespace
NAudio.Sequencing
Assembly
NAudio.Core.dll

The audio bridge that ties an EventTimeline<T> to a MixingSampleProvider. On each Read(Span<float>) call it delegates to EventBufferQuery for the upcoming buffer's events, invokes the dispatcher delegate with sample-accurate frame offsets, then reads from the mixer to fill the output.

public sealed class SequencedSampleProvider<T> : ISampleProvider

Type Parameters

T

Event payload type.

Inheritance
SequencedSampleProvider<T>
Implements
Inherited Members
Extension Methods

Remarks

Consumers that don't want to route events through a mixer (e.g. a VST3 instrument provider) should call Query<T>(EventTimeline<T>, ITempoMap, IPositionTransform, LoopRegion?, long, long, int, Action<SequencerEvent<T>, int>) directly instead of using this class.

Constructors

SequencedSampleProvider(Transport, EventTimeline<T>, WaveFormat, Action<SequencerEvent<T>, int>)

Creates a new sequenced sample provider.

public SequencedSampleProvider(Transport transport, EventTimeline<T> timeline, WaveFormat audioFormat, Action<SequencerEvent<T>, int> dispatcher)

Parameters

transport Transport

Drives playback position. Its sample rate must match audioFormat.

timeline EventTimeline<T>

The source of events.

audioFormat WaveFormat

Mixer output format. Must be IEEE float.

dispatcher Action<SequencerEvent<T>, int>

Invoked for each event whose effective fire-frame lands inside the upcoming buffer. The integer is the frame offset within the buffer (0 = first frame). The dispatcher typically wraps the payload's audio in an OffsetSampleProvider set to DelayBySamples = frameOffset * channels and adds it to Mixer. The Tick on the dispatched event is the effective tick (after the transform, and after loop iteration translation when looping).

Properties

Mixer

The internal mixer. Dispatchers add their voices here; external consumers can also add overlay providers (a metronome click, etc).

public MixingSampleProvider Mixer { get; }

Property Value

MixingSampleProvider

Timeline

The event source. The caller adds/removes events on the timeline directly.

public EventTimeline<T> Timeline { get; }

Property Value

EventTimeline<T>

Transform

The active position transform. Defaults to identity (no swing).

public IPositionTransform Transform { get; set; }

Property Value

IPositionTransform

Transport

The transport this provider is driven by.

public Transport Transport { get; }

Property Value

Transport

WaveFormat

Gets the WaveFormat of this Sample Provider.

public WaveFormat WaveFormat { get; }

Property Value

WaveFormat

The wave format.

Methods

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.