Skip to content

Providers

Axwabo edited this page Feb 25, 2026 · 4 revisions

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

  • StreamAudioProcessor encapsulates a WaveStream
  • 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.)
  • SampleProviderWrapper encapsulates an ISampleProvider and an optional IDiposable

NAudio Providers

Tip

You can leverage the below providers by using extension methods on a ProcessorChain

Some noteworthy NAudio providers are:

  • WdlResamplingSampleProvider changes the sample rate while retaining quality
  • StereoToMonoSampleProvider mixes the channels down to one
  • VolumeSampleProvider
  • OffsetSampleProvider has multiple properties:
    • DelayBy - silence to insert before playing the source
    • SkipOver - time to discard from the beginning of the source
    • Take - limits the maximum samples to read from the source
    • LeadOut - time of appended silence at the end
  • SmbPitchShiftingSampleProvider pitch-shifts the input

Getting Started

Playing Audio

Advanced

Audio Processors

FFmpeg

v1 Guides

Caution

v1 will be out of support soon.

Clone this wiki locally