Xeno-rat
Loading...
Searching...
No Matches
NAudio.Wave.WasapiOut Class Reference

Support for playback using Wasapi. More...

Inheritance diagram for NAudio.Wave.WasapiOut:
Collaboration diagram for NAudio.Wave.WasapiOut:

Public Member Functions

 WasapiOut ()
 WASAPI Out shared mode, default.
 
 WasapiOut (AudioClientShareMode shareMode, int latency)
 WASAPI Out using default audio endpoint.
 
 WasapiOut (AudioClientShareMode shareMode, bool useEventSync, int latency)
 WASAPI Out using default audio endpoint.
 
 WasapiOut (MMDevice device, AudioClientShareMode shareMode, bool useEventSync, int latency)
 Creates a new WASAPI Output.
 
long GetPosition ()
 Gets the current playback position in bytes.
 
void Play ()
 Starts playing the audio if the current playback state is not already playing. If the playback state is stopped, it starts a new thread to play the audio and sets the playback state to playing. If the playback state is not stopped, it sets the playback state to playing.
 
void Stop ()
 Stops the playback if it is currently running.
 
void Pause ()
 Pauses the playback if it is currently playing.
 
void Init (IWaveProvider waveProvider)
 Initializes the audio output with the specified waveProvider .
 
void Dispose ()
 Disposes the audio client and stops the rendering if it is currently running.
 

Properties

WaveFormat OutputWaveFormat [get, private set]
 Gets a Wave.WaveFormat instance indicating the format the hardware is using.
 
PlaybackState PlaybackState [get]
 Playback State.
 
float Volume [get, set]
 Volume.
 
AudioStreamVolume AudioStreamVolume [get]
 Retrieve the AudioStreamVolume object for this audio stream.
 
- Properties inherited from NAudio.Wave.IWavePlayer
- Properties inherited from NAudio.Wave.IWavePosition

Events

EventHandler< StoppedEventArgsPlaybackStopped
 Playback Stopped.
 
- Events inherited from NAudio.Wave.IWavePlayer
EventHandler< StoppedEventArgsPlaybackStopped
 Indicates that playback has gone into a stopped state due to reaching the end of the input stream or an error has been encountered during playback.
 

Private Member Functions

void PlayThread ()
 Plays the audio using the specified source provider and handles resampling if needed.
 
void RaisePlaybackStopped (Exception e)
 Raises the PlaybackStopped event with the specified exception.
 
void FillBuffer (IWaveProvider playbackProvider, int frameCount)
 Fills the buffer with audio data from the specified playback provider.
 
WaveFormat GetFallbackFormat ()
 Gets the fallback WaveFormat to be used in case the provided format is not supported, based on the supported formats by the audio device.
 

Static Private Member Functions

static MMDevice GetDefaultAudioEndpoint ()
 Retrieves the default audio endpoint for the specified data flow and role.
 

Private Attributes

AudioClient audioClient
 
readonly MMDevice mmDevice
 
readonly AudioClientShareMode shareMode
 
AudioRenderClient renderClient
 
IWaveProvider sourceProvider
 
int latencyMilliseconds
 
int bufferFrameCount
 
int bytesPerFrame
 
readonly bool isUsingEventSync
 
EventWaitHandle frameEventWaitHandle
 
byte[] readBuffer
 
volatile PlaybackState playbackState
 
Thread playThread
 
readonly SynchronizationContext syncContext
 
bool dmoResamplerNeeded
 

Detailed Description

Support for playback using Wasapi.

Constructor & Destructor Documentation

◆ WasapiOut() [1/4]

NAudio.Wave.WasapiOut.WasapiOut ( )
inline

WASAPI Out shared mode, default.

◆ WasapiOut() [2/4]

NAudio.Wave.WasapiOut.WasapiOut ( AudioClientShareMode shareMode,
int latency )
inline

WASAPI Out using default audio endpoint.

Parameters
shareModeShareMode - shared or exclusive
latencyDesired latency in milliseconds

◆ WasapiOut() [3/4]

NAudio.Wave.WasapiOut.WasapiOut ( AudioClientShareMode shareMode,
bool useEventSync,
int latency )
inline

WASAPI Out using default audio endpoint.

Parameters
shareModeShareMode - shared or exclusive
useEventSynctrue if sync is done with event. false use sleep.
latencyDesired latency in milliseconds

◆ WasapiOut() [4/4]

NAudio.Wave.WasapiOut.WasapiOut ( MMDevice device,
AudioClientShareMode shareMode,
bool useEventSync,
int latency )
inline

Creates a new WASAPI Output.

Parameters
deviceDevice to use
shareMode
useEventSynctrue if sync is done with event. false use sleep.
latencyDesired latency in milliseconds

Member Function Documentation

◆ Dispose()

void NAudio.Wave.WasapiOut.Dispose ( )
inline

Disposes the audio client and stops the rendering if it is currently running.

This method disposes the audio client and stops the rendering if it is currently running. It also sets the audio client and render client to null after disposal.

Here is the call graph for this function:

◆ FillBuffer()

void NAudio.Wave.WasapiOut.FillBuffer ( IWaveProvider playbackProvider,
int frameCount )
inlineprivate

Fills the buffer with audio data from the specified playback provider.

Parameters
playbackProviderThe IWaveProvider from which to read audio data.
frameCountThe number of audio frames to read and fill into the buffer.

This method fills the buffer with audio data from the specified playbackProvider . It then releases the buffer after filling it with the audio data. If the playbackProvider returns 0 on read, the playback state is set to Stopped.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetDefaultAudioEndpoint()

static MMDevice NAudio.Wave.WasapiOut.GetDefaultAudioEndpoint ( )
inlinestaticprivate

Retrieves the default audio endpoint for the specified data flow and role.

Exceptions
NotSupportedExceptionThrown when the operating system version is less than 6, indicating that WASAPI is supported only on Windows Vista and above.
Returns
The default audio endpoint for the specified data flow and role.

This method retrieves the default audio endpoint for the specified data flow and role using the Windows Audio Session API (WASAPI). If the operating system version is less than 6, a NotSupportedException is thrown, indicating that WASAPI is supported only on Windows Vista and above.

◆ GetFallbackFormat()

WaveFormat NAudio.Wave.WasapiOut.GetFallbackFormat ( )
inlineprivate

Gets the fallback WaveFormat to be used in case the provided format is not supported, based on the supported formats by the audio device.

Returns
The WaveFormat to be used as a fallback, based on the supported formats by the audio device.

This method first tries the provided sample rate, then the device's sample rate, and finally 44.1kHz and 48kHz if not already included in the list of sample rates to try. It also considers the provided channel count, the device's channel count, and 2 channels if not already included in the list of channel counts to try. Additionally, it includes the provided bit depth, 32-bit depth, 24-bit depth, and 16-bit depth if not already included in the list of bit depths to try. The method iterates through the combinations of sample rates, channel counts, and bit depths to find a supported WaveFormat by the audio device, and returns it as a fallback. If no supported format is found, a NotSupportedException is thrown with the message "Can't find a supported format to use".

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPosition()

long NAudio.Wave.WasapiOut.GetPosition ( )
inline

Gets the current playback position in bytes.

Returns
The current playback position in bytes.

This method retrieves the current playback position in bytes based on the current state of the audio playback. If the playback state is stopped, the position is 0. If the playback state is playing, the position is obtained from the audio clock client's adjusted position. If the playback state is paused, the position is obtained using the audio clock client's GetPosition method. The position is then calculated in bytes based on the output wave format's average bytes per second and the audio clock client's frequency.

Implements NAudio.Wave.IWavePosition.

Here is the call graph for this function:

◆ Init()

void NAudio.Wave.WasapiOut.Init ( IWaveProvider waveProvider)
inline

Initializes the audio output with the specified waveProvider .

Parameters
waveProviderThe wave provider to be used for audio output.

This method initializes the audio output with the provided waveProvider . It sets the output wave format based on the wave provider's wave format. If the shareMode is set to Exclusive, it checks if the format is supported and performs necessary fallbacks if required. If using EventSync, the setup is specific with shareMode and latency settings.

Implements NAudio.Wave.IWavePlayer.

Here is the call graph for this function:

◆ Pause()

void NAudio.Wave.WasapiOut.Pause ( )
inline

Pauses the playback if it is currently playing.

This method pauses the playback if the current state is set to PlaybackState.Playing. If the playback is not in the playing state, this method does nothing.

Implements NAudio.Wave.IWavePlayer.

◆ Play()

void NAudio.Wave.WasapiOut.Play ( )
inline

Starts playing the audio if the current playback state is not already playing. If the playback state is stopped, it starts a new thread to play the audio and sets the playback state to playing. If the playback state is not stopped, it sets the playback state to playing.

Implements NAudio.Wave.IWavePlayer.

Here is the call graph for this function:

◆ PlayThread()

void NAudio.Wave.WasapiOut.PlayThread ( )
inlineprivate

Plays the audio using the specified source provider and handles resampling if needed.

This method plays the audio using the specified source provider. If resampling is needed, it handles the resampling using the DMO stream. It fills the buffer with audio data and starts the audio client. It then continuously checks for available buffer space and fills the buffer accordingly. If an exception occurs during the process, it is caught and handled, and the playback is stopped.

Exceptions
ExceptionThrown if an error occurs during the playback process.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RaisePlaybackStopped()

void NAudio.Wave.WasapiOut.RaisePlaybackStopped ( Exception e)
inlineprivate

Raises the PlaybackStopped event with the specified exception.

Parameters
eThe exception that caused the playback to stop.
Exceptions
ArgumentNullExceptionThrown when the e is null.

This method raises the PlaybackStopped event with the specified exception. If a synchronization context is available, the event is raised on the synchronization context; otherwise, it is raised on the current thread.

Here is the caller graph for this function:

◆ Stop()

void NAudio.Wave.WasapiOut.Stop ( )
inline

Stops the playback if it is currently running.

Exceptions
InvalidOperationExceptionThrown when the playback state is not PlaybackState.Stopped.

This method stops the playback if it is currently running by setting the playbackState to PlaybackState.Stopped. It also waits for the play thread to join and sets it to null.

Implements NAudio.Wave.IWavePlayer.

Here is the caller graph for this function:

Member Data Documentation

◆ audioClient

AudioClient NAudio.Wave.WasapiOut.audioClient
private

◆ bufferFrameCount

int NAudio.Wave.WasapiOut.bufferFrameCount
private

◆ bytesPerFrame

int NAudio.Wave.WasapiOut.bytesPerFrame
private

◆ dmoResamplerNeeded

bool NAudio.Wave.WasapiOut.dmoResamplerNeeded
private

◆ frameEventWaitHandle

EventWaitHandle NAudio.Wave.WasapiOut.frameEventWaitHandle
private

◆ isUsingEventSync

readonly bool NAudio.Wave.WasapiOut.isUsingEventSync
private

◆ latencyMilliseconds

int NAudio.Wave.WasapiOut.latencyMilliseconds
private

◆ mmDevice

readonly MMDevice NAudio.Wave.WasapiOut.mmDevice
private

◆ playbackState

volatile PlaybackState NAudio.Wave.WasapiOut.playbackState
private

◆ playThread

Thread NAudio.Wave.WasapiOut.playThread
private

◆ readBuffer

byte [] NAudio.Wave.WasapiOut.readBuffer
private

◆ renderClient

AudioRenderClient NAudio.Wave.WasapiOut.renderClient
private

◆ shareMode

readonly AudioClientShareMode NAudio.Wave.WasapiOut.shareMode
private

◆ sourceProvider

IWaveProvider NAudio.Wave.WasapiOut.sourceProvider
private

◆ syncContext

readonly SynchronizationContext NAudio.Wave.WasapiOut.syncContext
private

Property Documentation

◆ AudioStreamVolume

AudioStreamVolume NAudio.Wave.WasapiOut.AudioStreamVolume
get

Retrieve the AudioStreamVolume object for this audio stream.

This returns the AudioStreamVolume object ONLY for shared audio streams.

Exceptions
InvalidOperationExceptionThis is thrown when an exclusive audio stream is being used.

◆ OutputWaveFormat

WaveFormat NAudio.Wave.WasapiOut.OutputWaveFormat
getprivate set

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

Implements NAudio.Wave.IWavePlayer.

◆ PlaybackState

PlaybackState NAudio.Wave.WasapiOut.PlaybackState
get

Playback State.

Implements NAudio.Wave.IWavePlayer.

◆ Volume

float NAudio.Wave.WasapiOut.Volume
getset

Volume.

Implements NAudio.Wave.IWavePlayer.

Event Documentation

◆ PlaybackStopped

EventHandler<StoppedEventArgs> NAudio.Wave.WasapiOut.PlaybackStopped

Playback Stopped.


The documentation for this class was generated from the following file: