Class WasapiOut
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
shareModeAudioClientShareModeShareMode - shared or exclusive
useEventSyncbooltrue if sync is done with event. false use sleep.
latencyintDesired latency in milliseconds
WasapiOut(AudioClientShareMode, int)
WASAPI Out using default audio endpoint
public WasapiOut(AudioClientShareMode shareMode, int latency)
Parameters
shareModeAudioClientShareModeShareMode - shared or exclusive
latencyintDesired latency in milliseconds
WasapiOut(MMDevice, AudioClientShareMode, bool, int)
Creates a new WASAPI Output
public WasapiOut(MMDevice device, AudioClientShareMode shareMode, bool useEventSync, int latency)
Parameters
deviceMMDeviceDevice to use
shareModeAudioClientShareModeuseEventSyncbooltrue if sync is done with event. false use sleep.
latencyintDesired latency in milliseconds
Properties
AudioStreamVolume
Retrieve the AudioStreamVolume object for this audio stream
public AudioStreamVolume AudioStreamVolume { get; }
Property Value
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
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
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
PlaybackState
Playback State
public PlaybackState PlaybackState { get; }
Property Value
Volume
Volume
public float Volume { get; set; }
Property Value
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
waveProviderIWaveProviderIWaveProvider 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