Table of Contents

Class WasapiOut

Namespace
NAudio.Wave
Assembly
NAudio.Wasapi.dll

Support for playback using Wasapi

[Obsolete("Use WasapiPlayerBuilder to create a WasapiPlayer instead. WasapiPlayer provides zero-copy buffers, MMCSS thread priority, and IAudioClient3 low-latency support.")]
public class WasapiOut : IWavePlayer, IDisposable, IWavePosition, IWaveLatency
Inheritance
WasapiOut
Implements
Inherited Members
Extension Methods

Constructors

WasapiOut()

WASAPI Out shared mode, default

public WasapiOut()

WasapiOut(AudioClientShareMode, bool, int)

WASAPI Out using default audio endpoint

public WasapiOut(AudioClientShareMode shareMode, bool useEventSync, int latency)

Parameters

shareMode AudioClientShareMode

ShareMode - shared or exclusive

useEventSync bool

true if sync is done with event. false use sleep.

latency int

Desired latency in milliseconds

WasapiOut(AudioClientShareMode, int)

WASAPI Out using default audio endpoint

public WasapiOut(AudioClientShareMode shareMode, int latency)

Parameters

shareMode AudioClientShareMode

ShareMode - shared or exclusive

latency int

Desired latency in milliseconds

WasapiOut(MMDevice, AudioClientShareMode, bool, int)

Creates a new WASAPI Output

public WasapiOut(MMDevice device, AudioClientShareMode shareMode, bool useEventSync, int latency)

Parameters

device MMDevice

Device to use

shareMode AudioClientShareMode
useEventSync bool

true if sync is done with event. false use sleep.

latency int

Desired latency in milliseconds

Properties

AudioStreamVolume

Retrieve the AudioStreamVolume object for this audio stream

public AudioStreamVolume AudioStreamVolume { get; }

Property Value

AudioStreamVolume

Remarks

This returns the AudioStreamVolume object ONLY for shared audio streams.

Exceptions

InvalidOperationException

This is thrown when an exclusive audio stream is being used.

AverageLatency

The steady-state latency from a sample being queued for output to it being emitted by the audio hardware, assuming uninterrupted playback. This is a property of the buffer configuration and the driver, not of the current playback state.

public TimeSpan AverageLatency { get; }

Property Value

TimeSpan

Remarks

Uses the latency reported by IAudioClient::GetStreamLatency at Init(IWaveProvider) time, falling back to the requested latency if the driver reported zero (as some Windows 10 builds do in shared mode).

CurrentLatency

The time that has elapsed since the sample currently emerging from the hardware was queued for output. In steady state this is approximately equal to AverageLatency; it differs during start-up, after an underrun, or when the host is filling buffers irregularly. Implementations that cannot meaningfully distinguish from the average are permitted to return AverageLatency.

public TimeSpan CurrentLatency { get; }

Property Value

TimeSpan

Remarks

Derived from IAudioClient::GetCurrentPadding: the count of frames still in the endpoint buffer corresponds directly to the delay between the most-recently-written sample and the play head. Returns AverageLatency when not playing.

OutputWaveFormat

Gets a WaveFormat instance indicating the format the hardware is using.

public WaveFormat OutputWaveFormat { get; }

Property Value

WaveFormat

PlaybackState

Playback State

public PlaybackState PlaybackState { get; }

Property Value

PlaybackState

Volume

Volume

public float Volume { get; set; }

Property Value

float

Methods

Dispose()

Dispose

public void Dispose()

GetPosition()

Gets the current position in bytes from the wave output device. (n.b. this is not the same thing as the position within your reader stream)

public long GetPosition()

Returns

long

Position in bytes

Init(IWaveProvider)

Initialize for playing the specified wave stream

public void Init(IWaveProvider waveProvider)

Parameters

waveProvider IWaveProvider

IWaveProvider to play

Pause()

Stop playback without flushing buffers

public void Pause()

Play()

Begin Playback

public void Play()

Stop()

Stop playback and flush buffers

public void Stop()

Events

PlaybackStopped

Playback Stopped

public event EventHandler<StoppedEventArgs> PlaybackStopped

Event Type

EventHandler<StoppedEventArgs>