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
TEvent 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
transportTransportDrives playback position. Its sample rate must match
audioFormat.timelineEventTimeline<T>The source of events.
audioFormatWaveFormatMixer output format. Must be IEEE float.
dispatcherAction<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 * channelsand 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
Timeline
The event source. The caller adds/removes events on the timeline directly.
public EventTimeline<T> Timeline { get; }
Property Value
Transform
The active position transform. Defaults to identity (no swing).
public IPositionTransform Transform { get; set; }
Property Value
Transport
The transport this provider is driven by.
public Transport Transport { get; }
Property Value
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
Returns
- int
The number of samples written. Return 0 to signal end of stream.