Table of Contents

Class WaveOut

Namespace
NAudio.Wave
Assembly
NAudio.WinMM.dll

WaveOut playback device using event callbacks

public class WaveOut : IWavePlayer, IDisposable, IWavePosition, IWaveLatency
Inheritance
WaveOut
Implements
Derived
Inherited Members
Extension Methods

Constructors

WaveOut()

Creates a new WaveOut device

public WaveOut()

Properties

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

Computed from the buffer configuration as (NumberOfBuffers - 0.5) * BufferMilliseconds: in steady state every queued buffer plus half of the one currently playing sits between the application and the speaker.

BufferMilliseconds

Milliseconds for each buffer. Recommended value is 100ms. Should be set before a call to Init

public int BufferMilliseconds { get; set; }

Property Value

int

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

Returns the elapsed time since the oldest in-queue buffer was filled — that is the buffer the hardware is currently draining. Falls back to AverageLatency when no buffer timestamps are available (e.g. immediately after Init(IWaveProvider)).

DeviceCount

Returns the number of Wave Out devices available in the system

public static int DeviceCount { get; }

Property Value

int

DeviceNumber

Gets or sets the device number Should be set before a call to Init This must be between -1 and DeviceCount - 1. -1 means stick to default device even default device is changed

public int DeviceNumber { get; set; }

Property Value

int

NumberOfBuffers

Gets or sets the number of buffers used Should be set before a call to Init

public int NumberOfBuffers { get; set; }

Property Value

int

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 for this device 1.0 is full scale

public float Volume { get; set; }

Property Value

float

Methods

Dispose()

Closes this WaveOut device

public void Dispose()

Dispose(bool)

Closes the WaveOut device and disposes of buffers

protected void Dispose(bool disposing)

Parameters

disposing bool

True if called from Dispose

~WaveOut()

Finalizer. Only called when user forgets to call Dispose

protected ~WaveOut()

GetCapabilities(int)

Retrieves the capabilities of a waveOut device

public static WaveOutCapabilities GetCapabilities(int devNumber)

Parameters

devNumber int

Device to test

Returns

WaveOutCapabilities

The WaveOut device capabilities

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 - it calls directly into waveOutGetPosition)

public long GetPosition()

Returns

long

Position in bytes

Init(IWaveProvider)

Initialises the WaveOut device

public void Init(IWaveProvider waveProvider)

Parameters

waveProvider IWaveProvider

The wave provider to play

Pause()

Pause the audio

public void Pause()

Play()

Start playing the audio from the WaveStream

public void Play()

Stop()

Stop and reset the WaveOut device

public void Stop()

Events

PlaybackStopped

Indicates playback has stopped automatically

public event EventHandler<StoppedEventArgs> PlaybackStopped

Event Type

EventHandler<StoppedEventArgs>