Providers - Axwabo/SecretLabNAudio GitHub Wiki
ISampleProvider
This is a minimal interface that allows essentially limitless ways to create or process samples.
It defines a wave format and an int Read(float[] buffer, int offset, int count) method.
[!TIP] See also: digital audio basics
When Read is called, it tries to fill the buffer with the amount of requested samples.
The method returns the read sample count, which can signal that the provider ended by returning 0 or an amount less than requested (e.g. there isn't enough data available).
SecretLabNAudio v2 introduced audio processors,
which are an extension of the ISampleProvider and IDisposable interface.
It's recommended to use audio processors when possible to avoid resource
management issues.
IAudioProcessor
An interface that combines ISampleProvider and IDisposable
Some built-in implementations are: Mixer AudioQueue StreamAudioProcessor
When a class implementing this interface is disposed, it should release
all resources used by it. Use the ProcessorLayer record to define
"child" processors (similar to Mixer)
that specify whether to dispose of the specific resource.
[!TIP] See also: streaming music
Intro to ProcessorChain
Use the ProcessorChain to stack "effects" (e.g. pitch, speed, etc.) while preserving access to the original source.
The original sources are exposed to let callers seek, or change the loop property via extension methods. This also lets consumers inspect the chain and see each step.
Built-In Processors
StreamAudioProcessorencapsulates aWaveStream- Mixer combines the output of multiple sample providers, as if they were playing at once
- AudioQueue plays the next provider when the current one ends
- ProcessorChain allows for different layers to be added to a provider (volume, pitch, etc.)
SampleProviderWrapperencapsulates anISampleProviderand an optionalIDiposable
NAudio Providers
[!TIP] You can leverage the below providers by using extension methods on a
ProcessorChain
Some noteworthy NAudio providers are:
WdlResamplingSampleProviderchanges the sample rate while retaining qualityStereoToMonoSampleProvidermixes the channels down to oneVolumeSampleProviderOffsetSampleProviderhas multiple properties:DelayBy- silence to insert before playing the sourceSkipOver- time to discard from the beginning of the sourceTake- limits the maximum samples to read from the sourceLeadOut- time of appended silence at the end
SmbPitchShiftingSampleProviderpitch-shifts the input