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

Alternative WaveOut class, making use of the Event callback. More...

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

Public Member Functions

 WaveOutEvent ()
 Opens a WaveOut device.
 
void Init (IWaveProvider waveProvider)
 Initializes the WaveOut device with the specified wave provider.
 
void Play ()
 Plays the audio.
 
void Pause ()
 Pauses the audio playback if the current state is playing.
 
void Stop ()
 Stops the playback.
 
long GetPosition ()
 Gets the current position in bytes of the audio playback.
 
void Dispose ()
 Disposes the resources used by the WaveOut device.
 

Protected Member Functions

void Dispose (bool disposing)
 Closes the WaveOut device and disposes of buffers.
 

Properties

int DesiredLatency [get, set]
 Gets or sets the desired latency in milliseconds Should be set before a call to Init.
 
int NumberOfBuffers [get, set]
 Gets or sets the number of buffers used Should be set before a call to Init.
 
int DeviceNumber = -1 [get, set]
 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.
 
WaveFormat OutputWaveFormat [get]
 Gets a Wave.WaveFormat instance indicating the format the hardware is using.
 
PlaybackState PlaybackState [get]
 Playback State.
 
float Volume [get, set]
 Volume for this device 1.0 is full scale.
 
- Properties inherited from NAudio.Wave.IWavePlayer
- Properties inherited from NAudio.Wave.IWavePosition

Events

EventHandler< StoppedEventArgsPlaybackStopped
 Indicates playback has stopped automatically.
 
- 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 PlaybackThread ()
 Executes the DoPlayback method in a separate thread and raises the PlaybackStopped event upon completion or in case of an exception.
 
void DoPlayback ()
 Performs the audio playback operation.
 
void Resume ()
 Resumes playback if the current state is paused.
 
void CloseWaveOut ()
 Closes the wave output device and releases associated resources.
 
void DisposeBuffers ()
 Disposes all the buffers and sets them to null.
 
 ~WaveOutEvent ()
 Finalizer. Only called when user forgets to call Dispose
 
void RaisePlaybackStoppedEvent (Exception e)
 Raises the PlaybackStopped event with the specified exception.
 

Private Attributes

readonly object waveOutLock
 
readonly SynchronizationContext syncContext
 
IntPtr hWaveOut
 
WaveOutBuffer[] buffers
 
IWaveProvider waveStream
 
volatile PlaybackState playbackState
 
AutoResetEvent callbackEvent
 

Detailed Description

Alternative WaveOut class, making use of the Event callback.

Constructor & Destructor Documentation

◆ WaveOutEvent()

NAudio.Wave.WaveOutEvent.WaveOutEvent ( )
inline

Opens a WaveOut device.

◆ ~WaveOutEvent()

NAudio.Wave.WaveOutEvent.~WaveOutEvent ( )
inlineprivate

Finalizer. Only called when user forgets to call Dispose

Here is the call graph for this function:

Member Function Documentation

◆ CloseWaveOut()

void NAudio.Wave.WaveOutEvent.CloseWaveOut ( )
inlineprivate

Closes the wave output device and releases associated resources.

This method closes the wave output device and releases any associated resources. If the callbackEvent is not null, it is closed and set to null. The method then locks the waveOutLock and checks if the hWaveOut is not equal to IntPtr.Zero. If it is not, the WaveInterop.waveOutClose method is called to close the wave output device, and hWaveOut is set to IntPtr.Zero.

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

◆ Dispose() [1/2]

void NAudio.Wave.WaveOutEvent.Dispose ( )
inline

Disposes the resources used by the WaveOut device.

Parameters
disposingA boolean value indicating whether the method is being called from the Dispose method.

This method stops the WaveOut device and disposes the buffers used by the device. If disposing is true, it also closes the WaveOut device.

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

◆ Dispose() [2/2]

void NAudio.Wave.WaveOutEvent.Dispose ( bool disposing)
inlineprotected

Closes the WaveOut device and disposes of buffers.

Parameters
disposingTrue if called from Dispose
Here is the call graph for this function:

◆ DisposeBuffers()

void NAudio.Wave.WaveOutEvent.DisposeBuffers ( )
inlineprivate

Disposes all the buffers and sets them to null.

This method disposes all the buffers in the collection and sets the collection to null.

Here is the caller graph for this function:

◆ DoPlayback()

void NAudio.Wave.WaveOutEvent.DoPlayback ( )
inlineprivate

Performs the audio playback operation.

This method continuously checks the playback state and waits for the callback event with the desired latency. If the playback state is playing and the callback event times out, a warning message is logged. It also requeues any buffers that are returned and checks if all buffers have been queued, indicating the end of playback. If all buffers have been queued, the playback state is set to stopped and the callback event is set.

Here is the caller graph for this function:

◆ GetPosition()

long NAudio.Wave.WaveOutEvent.GetPosition ( )

Gets the current position in bytes of the audio playback.

Returns
The current position in bytes of the audio playback.

Implements NAudio.Wave.IWavePosition.

◆ Init()

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

Initializes the WaveOut device with the specified wave provider.

Parameters
waveProviderThe wave provider to be initialized.
Exceptions
InvalidOperationExceptionThrown when attempting to re-initialize during playback.

This method initializes the WaveOut device with the specified wave provider, allocating buffers and setting up the necessary event handling. If the playback state is not stopped, an InvalidOperationException is thrown, indicating that re-initialization during playback is not allowed. If the WaveOut device is already initialized, it is cleaned up and re-initialized with the new wave provider.

Implements NAudio.Wave.IWavePlayer.

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

◆ Pause()

void NAudio.Wave.WaveOutEvent.Pause ( )
inline

Pauses the audio playback if the current state is playing.

Exceptions
MmExceptionThrown when an error occurs while pausing the audio playback.

If the current playback state is playing, this method pauses the audio playback. It sets the playback state to paused to avoid a deadlock problem with some drivers and then pauses the audio output using the WaveInterop.waveOutPause method. If an error occurs during the pause operation, a MmException is thrown with details about the error.

Implements NAudio.Wave.IWavePlayer.

Here is the call graph for this function:

◆ Play()

void NAudio.Wave.WaveOutEvent.Play ( )
inline

Plays the audio.

Exceptions
InvalidOperationExceptionThrown when buffers or waveStream is null. Must call Init first.

If the playbackState is stopped, it sets the state to Playing and starts the playback thread using ThreadPool.QueueUserWorkItem. If the playbackState is paused, it resumes the playback and starts the playback thread using ThreadPool.QueueUserWorkItem.

Implements NAudio.Wave.IWavePlayer.

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

◆ PlaybackThread()

void NAudio.Wave.WaveOutEvent.PlaybackThread ( )
inlineprivate

Executes the DoPlayback method in a separate thread and raises the PlaybackStopped event upon completion or in case of an exception.

This method encapsulates the logic for executing the DoPlayback method in a separate thread. Upon completion or in case of an exception, the method updates the playbackState to Stopped and raises the PlaybackStopped event, passing any caught exception as an argument.

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

◆ RaisePlaybackStoppedEvent()

void NAudio.Wave.WaveOutEvent.RaisePlaybackStoppedEvent ( Exception e)
inlineprivate

Raises the PlaybackStopped event with the specified exception.

Parameters
eThe exception that caused the playback to stop.
Exceptions
ArgumentNullExceptionThrown when the exception 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:

◆ Resume()

void NAudio.Wave.WaveOutEvent.Resume ( )
inlineprivate

Resumes playback if the current state is paused.

Exceptions
MmExceptionThrown when an error occurs while trying to resume playback.

If the current playback state is paused, this method resumes the playback by calling the waveOutRestart function from WaveInterop. The method locks the waveOutLock object to ensure thread safety while calling the waveOutRestart function. If an error occurs during the waveOutRestart call, a MmException is thrown with the corresponding error message. After successful resumption of playback, the playbackState is set to Playing.

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

◆ Stop()

void NAudio.Wave.WaveOutEvent.Stop ( )
inline

Stops the playback.

Exceptions
MmExceptionThrown when an error occurs during the waveOutReset operation.

If the current playback state is not stopped, this method sets the playback state to stopped and resets the waveOut device. This method also signals the callback event to ensure that the thread exits.

Implements NAudio.Wave.IWavePlayer.

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

Member Data Documentation

◆ buffers

WaveOutBuffer [] NAudio.Wave.WaveOutEvent.buffers
private

◆ callbackEvent

AutoResetEvent NAudio.Wave.WaveOutEvent.callbackEvent
private

◆ hWaveOut

IntPtr NAudio.Wave.WaveOutEvent.hWaveOut
private

◆ playbackState

volatile PlaybackState NAudio.Wave.WaveOutEvent.playbackState
private

◆ syncContext

readonly SynchronizationContext NAudio.Wave.WaveOutEvent.syncContext
private

◆ waveOutLock

readonly object NAudio.Wave.WaveOutEvent.waveOutLock
private

◆ waveStream

IWaveProvider NAudio.Wave.WaveOutEvent.waveStream
private

Property Documentation

◆ DesiredLatency

int NAudio.Wave.WaveOutEvent.DesiredLatency
getset

Gets or sets the desired latency in milliseconds Should be set before a call to Init.

◆ DeviceNumber

int NAudio.Wave.WaveOutEvent.DeviceNumber = -1
getset

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.

◆ NumberOfBuffers

int NAudio.Wave.WaveOutEvent.NumberOfBuffers
getset

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

◆ OutputWaveFormat

WaveFormat NAudio.Wave.WaveOutEvent.OutputWaveFormat
get

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

Implements NAudio.Wave.IWavePlayer.

◆ PlaybackState

PlaybackState NAudio.Wave.WaveOutEvent.PlaybackState
get

Playback State.

Implements NAudio.Wave.IWavePlayer.

◆ Volume

float NAudio.Wave.WaveOutEvent.Volume
getset

Volume for this device 1.0 is full scale.

Implements NAudio.Wave.IWavePlayer.

Event Documentation

◆ PlaybackStopped

EventHandler<StoppedEventArgs> NAudio.Wave.WaveOutEvent.PlaybackStopped

Indicates playback has stopped automatically.


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