NativeDirectSoundOut using DirectSound COM interop. Contact author: Alexandre Mutel - alexandre_mutel at yahoo.fr Modified by: Graham "Gee" Plumb.
More...
|
class | BufferCaps |
|
class | BufferDescription |
|
struct | DirectSoundBufferPositionNotify |
|
interface | IDirectSound |
| IDirectSound interface.
|
|
interface | IDirectSoundBuffer |
| IDirectSoundBuffer interface.
|
|
interface | IDirectSoundNotify |
| IDirectSoundNotify interface.
|
|
|
| DirectSoundOut () |
| Initializes a new instance of the DirectSoundOut class.
|
|
| DirectSoundOut (Guid device) |
| Initializes a new instance of the DirectSoundOut class.
|
|
| DirectSoundOut (int latency) |
| Initializes a new instance of the DirectSoundOut class.
|
|
| DirectSoundOut (Guid device, int latency) |
| Initializes a new instance of the DirectSoundOut class. (40ms seems to work under Vista).
|
|
void | Play () |
| Starts playing the audio. If the playback state is stopped, it creates a new thread to process samples and starts playing.
|
|
void | Stop () |
| Stops the playback.
|
|
void | Pause () |
| Pauses the playback.
|
|
long | GetPosition () |
| Retrieves the current playback position in bytes.
|
|
void | Init (IWaveProvider waveProvider) |
| Initializes the wave stream and wave format using the provided waveProvider .
|
|
void | Dispose () |
| Stops the object and releases resources, and suppresses the finalization of the object.
|
|
|
static readonly Guid | DSDEVID_DefaultPlayback = new Guid("DEF00000-9C6D-47ED-AAF1-4DDA8F2B5C03") |
| DirectSound default playback device GUID.
|
|
static readonly Guid | DSDEVID_DefaultCapture = new Guid("DEF00001-9C6D-47ED-AAF1-4DDA8F2B5C03") |
| DirectSound default capture device GUID.
|
|
static readonly Guid | DSDEVID_DefaultVoicePlayback = new Guid("DEF00002-9C6D-47ED-AAF1-4DDA8F2B5C03") |
| DirectSound default device for voice playback.
|
|
static readonly Guid | DSDEVID_DefaultVoiceCapture = new Guid("DEF00003-9C6D-47ED-AAF1-4DDA8F2B5C03") |
| DirectSound default device for voice capture.
|
|
|
| ~DirectSoundOut () |
| Releases unmanaged resources and performs other cleanup operations before the DirectSoundOut is reclaimed by garbage collection.
|
|
void | InitializeDirectSound () |
| Initializes the DirectSound and creates primary and secondary sound buffers for audio playback.
|
|
bool | IsBufferLost () |
| Checks if the secondary buffer is lost and returns a boolean value indicating the result.
|
|
int | MsToBytes (int ms) |
| Converts milliseconds to bytes based on the average bytes per second of the wave format.
|
|
void | PlaybackThreadFunc () |
| This method represents the playback thread function. It initializes the DirectSound, feeds the audio samples, and handles the playback state.
|
|
void | RaisePlaybackStopped (Exception e) |
| Raises the PlaybackStopped event with the specified exception.
|
|
void | StopPlayback () |
| Stops the playback of the sound.
|
|
void | CleanUpSecondaryBuffer () |
| Cleans up the secondary buffer by filling it with silence data.
|
|
int | Feed (int bytesToCopy) |
| Reads data from the wave stream and copies it to the secondary buffer. If the buffer is lost, it is restored. If in Paused state, the bufferSamples are cleared.
|
|
static void | DirectSoundCreate (ref Guid GUID, [Out, MarshalAs(UnmanagedType.Interface)] out IDirectSound directSound, IntPtr pUnkOuter) |
| Creates a DirectSound object that represents the default sound device.
|
|
delegate bool | DSEnumCallback (IntPtr lpGuid, IntPtr lpcstrDescription, IntPtr lpcstrModule, IntPtr lpContext) |
| The DSEnumCallback function is an application-defined callback function that enumerates the DirectSound drivers. The system calls this function in response to the application's call to the DirectSoundEnumerate or DirectSoundCaptureEnumerate function.
|
|
static void | DirectSoundEnumerate (DSEnumCallback lpDSEnumCallback, IntPtr lpContext) |
| Enumerates the DirectSound drivers installed on the system and calls the specified callback function for each driver found.
|
|
static IntPtr | GetDesktopWindow () |
| Retrieves a handle to the desktop window. The desktop window covers the entire screen. The desktop window is the area on top of which other windows are painted.
|
|
|
static bool | EnumCallback (IntPtr lpGuid, IntPtr lpcstrDescription, IntPtr lpcstrModule, IntPtr lpContext) |
| Callback function for enumerating DirectSound devices.
|
|
NativeDirectSoundOut using DirectSound COM interop. Contact author: Alexandre Mutel - alexandre_mutel at yahoo.fr Modified by: Graham "Gee" Plumb.
◆ DirectSoundOut() [1/4]
NAudio.Wave.DirectSoundOut.DirectSoundOut |
( |
| ) |
|
|
inline |
Initializes a new instance of the DirectSoundOut class.
◆ DirectSoundOut() [2/4]
NAudio.Wave.DirectSoundOut.DirectSoundOut |
( |
Guid | device | ) |
|
|
inline |
Initializes a new instance of the DirectSoundOut class.
◆ DirectSoundOut() [3/4]
NAudio.Wave.DirectSoundOut.DirectSoundOut |
( |
int | latency | ) |
|
|
inline |
Initializes a new instance of the DirectSoundOut class.
◆ DirectSoundOut() [4/4]
NAudio.Wave.DirectSoundOut.DirectSoundOut |
( |
Guid | device, |
|
|
int | latency ) |
|
inline |
Initializes a new instance of the DirectSoundOut class. (40ms seems to work under Vista).
- Parameters
-
latency | The latency. |
device | Selected device |
◆ ~DirectSoundOut()
NAudio.Wave.DirectSoundOut.~DirectSoundOut |
( |
| ) |
|
|
inlineprivate |
Releases unmanaged resources and performs other cleanup operations before the DirectSoundOut is reclaimed by garbage collection.
◆ CleanUpSecondaryBuffer()
void NAudio.Wave.DirectSoundOut.CleanUpSecondaryBuffer |
( |
| ) |
|
|
inlineprivate |
Cleans up the secondary buffer by filling it with silence data.
If the secondary buffer is not null, this method locks the buffer, fills it with silence data, and then unlocks it. The silence data is created as an array of bytes with a size equal to the total samples size of the buffer. The method first locks the secondary buffer to access its memory, then copies the silence data into the buffer, and finally unlocks the buffer.
◆ DirectSoundCreate()
static void NAudio.Wave.DirectSoundOut.DirectSoundCreate |
( |
ref Guid | GUID, |
|
|
[Out, MarshalAs(UnmanagedType.Interface)] out IDirectSound | directSound, |
|
|
IntPtr | pUnkOuter ) |
|
private |
Creates a DirectSound object that represents the default sound device.
- Parameters
-
GUID | The GUID of the sound device. |
directSound | When this method returns, contains the IDirectSound interface for the created sound device. |
pUnkOuter | Reserved for future use. Must be null . |
- Exceptions
-
ArgumentException | Thrown when the GUID is not a valid GUID. |
ExternalException | Thrown when an error occurred while creating the DirectSound object. |
◆ DirectSoundEnumerate()
static void NAudio.Wave.DirectSoundOut.DirectSoundEnumerate |
( |
DSEnumCallback | lpDSEnumCallback, |
|
|
IntPtr | lpContext ) |
|
private |
Enumerates the DirectSound drivers installed on the system and calls the specified callback function for each driver found.
- Parameters
-
lpDSEnumCallback | A pointer to the callback function that will be called for each DirectSound driver found. |
lpContext | An application-defined value that will be passed to the callback function. |
This method calls the specified callback function lpDSEnumCallback for each DirectSound driver found on the system. The lpContext parameter is an application-defined value that will be passed to the callback function.
◆ Dispose()
void NAudio.Wave.DirectSoundOut.Dispose |
( |
| ) |
|
|
inline |
Stops the object and releases resources, and suppresses the finalization of the object.
This method stops the object and releases any resources it is using. It also suppresses the finalization of the object, preventing the finalizer from being called.
◆ DSEnumCallback()
delegate bool NAudio.Wave.DirectSoundOut.DSEnumCallback |
( |
IntPtr | lpGuid, |
|
|
IntPtr | lpcstrDescription, |
|
|
IntPtr | lpcstrModule, |
|
|
IntPtr | lpContext ) |
|
private |
The DSEnumCallback function is an application-defined callback function that enumerates the DirectSound drivers. The system calls this function in response to the application's call to the DirectSoundEnumerate or DirectSoundCaptureEnumerate function.
- Parameters
-
lpGuid | Address of the GUID that identifies the device being enumerated, or NULL for the primary device. This value can be passed to the DirectSoundCreate8 or DirectSoundCaptureCreate8 function to create a device object for that driver. |
lpcstrDescription | Address of a null-terminated string that provides a textual description of the DirectSound device. |
lpcstrModule | Address of a null-terminated string that specifies the module name of the DirectSound driver corresponding to this device. |
lpContext | Address of application-defined data. This is the pointer passed to DirectSoundEnumerate or DirectSoundCaptureEnumerate as the lpContext parameter. |
- Returns
- Returns TRUE to continue enumerating drivers, or FALSE to stop.
◆ EnumCallback()
static bool NAudio.Wave.DirectSoundOut.EnumCallback |
( |
IntPtr | lpGuid, |
|
|
IntPtr | lpcstrDescription, |
|
|
IntPtr | lpcstrModule, |
|
|
IntPtr | lpContext ) |
|
inlinestaticprivate |
Callback function for enumerating DirectSound devices.
- Parameters
-
lpGuid | A pointer to the GUID of the enumerated device. |
lpcstrDescription | A pointer to the description of the enumerated device. |
lpcstrModule | A pointer to the module name of the enumerated device, or null if not available. |
lpContext | A pointer to application-defined data. |
- Returns
- True if the enumeration should continue; otherwise, false.
This callback function is used for enumerating DirectSound devices. It creates a new DirectSoundDeviceInfo object, populates it with the provided information, and adds it to the devices collection. If the GUID pointer is IntPtr.Zero, the device's GUID is set to Guid.Empty; otherwise, it is constructed from the provided bytes. The description and module name are obtained from the provided pointers and assigned to the device object. The function returns true to continue the enumeration.
◆ Feed()
int NAudio.Wave.DirectSoundOut.Feed |
( |
int | bytesToCopy | ) |
|
|
inlineprivate |
Reads data from the wave stream and copies it to the secondary buffer. If the buffer is lost, it is restored. If in Paused state, the bufferSamples are cleared.
- Parameters
-
bytesToCopy | The number of bytes to copy from the wave stream to the secondary buffer. |
- Returns
- The number of bytes actually read from the wave stream and copied to the secondary buffer.
This method first checks if the buffer is lost and restores it if necessary. If in Paused state, it clears the bufferSamples. It then reads data from the wave stream and copies it to the secondary buffer. The method locks a portion of the SecondaryBuffer and copies the data back to it. Finally, it unlocks the SecondaryBuffer and returns the number of bytes read from the wave stream.
◆ GetDesktopWindow()
static IntPtr NAudio.Wave.DirectSoundOut.GetDesktopWindow |
( |
| ) |
|
|
private |
Retrieves a handle to the desktop window. The desktop window covers the entire screen. The desktop window is the area on top of which other windows are painted.
- Returns
- A handle to the desktop window.
◆ GetPosition()
long NAudio.Wave.DirectSoundOut.GetPosition |
( |
| ) |
|
|
inline |
Retrieves the current playback position in bytes.
- Returns
- The current playback position in bytes. Returns 0 if the playback state is stopped or if the secondary buffer is null.
This method retrieves the current play cursor and write cursor from the secondary buffer and calculates the current playback position by adding the bytes played to the play cursor. If the playback state is stopped or if the secondary buffer is null, the method returns 0.
◆ Init()
void NAudio.Wave.DirectSoundOut.Init |
( |
IWaveProvider | waveProvider | ) |
|
|
inline |
Initializes the wave stream and wave format using the provided waveProvider .
- Parameters
-
waveProvider | The wave provider to be initialized. |
This method initializes the wave stream and wave format using the provided waveProvider .
Implements NAudio.Wave.IWavePlayer.
◆ InitializeDirectSound()
void NAudio.Wave.DirectSoundOut.InitializeDirectSound |
( |
| ) |
|
|
inlineprivate |
Initializes the DirectSound and creates primary and secondary sound buffers for audio playback.
This method initializes the DirectSound by creating primary and secondary sound buffers for audio playback. It sets the cooperative level to PRIORITY and creates the primary sound buffer for looping playback. It also creates the secondary sound buffer with double buffering notification for audio playback.
◆ IsBufferLost()
bool NAudio.Wave.DirectSoundOut.IsBufferLost |
( |
| ) |
|
|
inlineprivate |
Checks if the secondary buffer is lost and returns a boolean value indicating the result.
- Returns
- True if the secondary buffer is lost; otherwise, false.
◆ MsToBytes()
int NAudio.Wave.DirectSoundOut.MsToBytes |
( |
int | ms | ) |
|
|
inlineprivate |
Converts milliseconds to bytes based on the average bytes per second of the wave format.
- Parameters
-
ms | The time in milliseconds to be converted to bytes. |
- Returns
- The equivalent number of bytes for the given time in milliseconds, based on the wave format's average bytes per second.
◆ Pause()
void NAudio.Wave.DirectSoundOut.Pause |
( |
| ) |
|
|
inline |
Pauses the playback.
This method pauses the playback by setting the playbackState to PlaybackState.Paused.
Implements NAudio.Wave.IWavePlayer.
◆ Play()
void NAudio.Wave.DirectSoundOut.Play |
( |
| ) |
|
|
inline |
Starts playing the audio. If the playback state is stopped, it creates a new thread to process samples and starts playing.
Implements NAudio.Wave.IWavePlayer.
◆ PlaybackThreadFunc()
void NAudio.Wave.DirectSoundOut.PlaybackThreadFunc |
( |
| ) |
|
|
inlineprivate |
This method represents the playback thread function. It initializes the DirectSound, feeds the audio samples, and handles the playback state.
- Exceptions
-
Exception | Thrown when there is an error during the playback process, such as a DirectSound buffer timeout. |
◆ RaisePlaybackStopped()
void NAudio.Wave.DirectSoundOut.RaisePlaybackStopped |
( |
Exception | e | ) |
|
|
inlineprivate |
Raises the PlaybackStopped event with the specified exception.
- Parameters
-
e | The exception that caused the playback to stop. |
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.
- Exceptions
-
ArgumentNullException | Thrown when the specified exception is null. |
◆ Stop()
void NAudio.Wave.DirectSoundOut.Stop |
( |
| ) |
|
|
inline |
Stops the playback.
This method attempts to stop the playback by acquiring a lock on the m_LockObject for 50 milliseconds using Monitor.TryEnter(object, int). If successful, it sets the playbackState to PlaybackState.Stopped and releases the lock. If unsuccessful, it aborts the notifyThread if it exists.
Implements NAudio.Wave.IWavePlayer.
◆ StopPlayback()
void NAudio.Wave.DirectSoundOut.StopPlayback |
( |
| ) |
|
|
inlineprivate |
Stops the playback of the sound.
This method stops the playback of the sound by releasing the secondary buffer, stopping the secondary buffer, releasing the primary sound buffer, and releasing the DirectSound object.
◆ bytesPlayed
long NAudio.Wave.DirectSoundOut.bytesPlayed |
|
private |
◆ desiredLatency
int NAudio.Wave.DirectSoundOut.desiredLatency |
|
private |
◆ device
Guid NAudio.Wave.DirectSoundOut.device |
|
private |
◆ devices
◆ directSound
IDirectSound NAudio.Wave.DirectSoundOut.directSound = null |
|
private |
◆ DSDEVID_DefaultCapture
readonly Guid NAudio.Wave.DirectSoundOut.DSDEVID_DefaultCapture = new Guid("DEF00001-9C6D-47ED-AAF1-4DDA8F2B5C03") |
|
static |
DirectSound default capture device GUID.
◆ DSDEVID_DefaultPlayback
readonly Guid NAudio.Wave.DirectSoundOut.DSDEVID_DefaultPlayback = new Guid("DEF00000-9C6D-47ED-AAF1-4DDA8F2B5C03") |
|
static |
DirectSound default playback device GUID.
◆ DSDEVID_DefaultVoiceCapture
readonly Guid NAudio.Wave.DirectSoundOut.DSDEVID_DefaultVoiceCapture = new Guid("DEF00003-9C6D-47ED-AAF1-4DDA8F2B5C03") |
|
static |
DirectSound default device for voice capture.
◆ DSDEVID_DefaultVoicePlayback
readonly Guid NAudio.Wave.DirectSoundOut.DSDEVID_DefaultVoicePlayback = new Guid("DEF00002-9C6D-47ED-AAF1-4DDA8F2B5C03") |
|
static |
DirectSound default device for voice playback.
◆ endEventWaitHandle
EventWaitHandle NAudio.Wave.DirectSoundOut.endEventWaitHandle |
|
private |
◆ frameEventWaitHandle1
EventWaitHandle NAudio.Wave.DirectSoundOut.frameEventWaitHandle1 |
|
private |
◆ frameEventWaitHandle2
EventWaitHandle NAudio.Wave.DirectSoundOut.frameEventWaitHandle2 |
|
private |
◆ m_LockObject
Object NAudio.Wave.DirectSoundOut.m_LockObject = new Object() |
|
private |
◆ nextSamplesWriteIndex
int NAudio.Wave.DirectSoundOut.nextSamplesWriteIndex |
|
private |
◆ notifyThread
Thread NAudio.Wave.DirectSoundOut.notifyThread |
|
private |
◆ playbackState
◆ primarySoundBuffer
IDirectSoundBuffer NAudio.Wave.DirectSoundOut.primarySoundBuffer = null |
|
private |
◆ samples
byte [] NAudio.Wave.DirectSoundOut.samples |
|
private |
◆ samplesFrameSize
int NAudio.Wave.DirectSoundOut.samplesFrameSize |
|
private |
◆ samplesTotalSize
int NAudio.Wave.DirectSoundOut.samplesTotalSize |
|
private |
◆ secondaryBuffer
IDirectSoundBuffer NAudio.Wave.DirectSoundOut.secondaryBuffer = null |
|
private |
◆ syncContext
SynchronizationContext NAudio.Wave.DirectSoundOut.syncContext |
|
private |
◆ waveFormat
◆ waveStream
◆ Devices
Gets the DirectSound output devices in the system.
◆ OutputWaveFormat
WaveFormat NAudio.Wave.DirectSoundOut.OutputWaveFormat |
|
get |
◆ PlaybackPosition
TimeSpan NAudio.Wave.DirectSoundOut.PlaybackPosition |
|
get |
Gets the current position from the wave output device.
◆ PlaybackState
◆ Volume
float NAudio.Wave.DirectSoundOut.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.Core/Wave/WaveOutputs/DirectSoundOut.cs