Support for playback using Wasapi.
More...
|
| 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.
|
|
|
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.
|
|
Support for playback using Wasapi.
◆ WasapiOut() [1/4]
NAudio.Wave.WasapiOut.WasapiOut |
( |
| ) |
|
|
inline |
WASAPI Out shared mode, default.
◆ WasapiOut() [2/4]
WASAPI Out using default audio endpoint.
- Parameters
-
shareMode | ShareMode - shared or exclusive |
latency | Desired latency in milliseconds |
◆ WasapiOut() [3/4]
WASAPI Out using default audio endpoint.
- Parameters
-
shareMode | ShareMode - shared or exclusive |
useEventSync | true if sync is done with event. false use sleep. |
latency | Desired latency in milliseconds |
◆ WasapiOut() [4/4]
Creates a new WASAPI Output.
- Parameters
-
device | Device to use |
shareMode | |
useEventSync | true if sync is done with event. false use sleep. |
latency | Desired latency in milliseconds |
◆ 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.
◆ FillBuffer()
void NAudio.Wave.WasapiOut.FillBuffer |
( |
IWaveProvider | playbackProvider, |
|
|
int | frameCount ) |
|
inlineprivate |
Fills the buffer with audio data from the specified playback provider.
- Parameters
-
playbackProvider | The IWaveProvider from which to read audio data. |
frameCount | The 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.
◆ GetDefaultAudioEndpoint()
static MMDevice NAudio.Wave.WasapiOut.GetDefaultAudioEndpoint |
( |
| ) |
|
|
inlinestaticprivate |
Retrieves the default audio endpoint for the specified data flow and role.
- Exceptions
-
NotSupportedException | Thrown 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".
◆ 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.
◆ Init()
Initializes the audio output with the specified waveProvider .
- Parameters
-
waveProvider | The 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.
◆ 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.
◆ 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
-
Exception | Thrown if an error occurs during the playback process. |
◆ RaisePlaybackStopped()
void NAudio.Wave.WasapiOut.RaisePlaybackStopped |
( |
Exception | e | ) |
|
|
inlineprivate |
Raises the PlaybackStopped event with the specified exception.
- Parameters
-
e | The exception that caused the playback to stop. |
- Exceptions
-
ArgumentNullException | Thrown 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.
◆ Stop()
void NAudio.Wave.WasapiOut.Stop |
( |
| ) |
|
|
inline |
Stops the playback if it is currently running.
- Exceptions
-
InvalidOperationException | Thrown 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.
◆ audioClient
◆ 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
◆ playThread
Thread NAudio.Wave.WasapiOut.playThread |
|
private |
◆ readBuffer
byte [] NAudio.Wave.WasapiOut.readBuffer |
|
private |
◆ renderClient
◆ shareMode
◆ sourceProvider
◆ syncContext
readonly SynchronizationContext NAudio.Wave.WasapiOut.syncContext |
|
private |
◆ AudioStreamVolume
Retrieve the AudioStreamVolume object for this audio stream.
This returns the AudioStreamVolume object ONLY for shared audio streams.
- Exceptions
-
InvalidOperationException | This is thrown when an exclusive audio stream is being used. |
◆ OutputWaveFormat
◆ PlaybackState
◆ Volume
float NAudio.Wave.WasapiOut.Volume |
|
getset |
◆ PlaybackStopped
The documentation for this class was generated from the following file:
- /Users/sumansaurabh/Documents/my-startup/xeno-rat/Plugins/LiveMicrophone/lib/NAudio.Wasapi/WasapiOut.cs