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

ASIO Out Player. New implementation using an internal C# binding. More...

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

Public Member Functions

 AsioOut ()
 Initializes a new instance of the AsioOut class with the first available ASIO Driver.
 
 AsioOut (string driverName)
 Initializes a new instance of the AsioOut class with the driver name.
 
 AsioOut (int driverIndex)
 Opens an ASIO output device.
 
void Dispose ()
 Releases the resources used by the driver and sets the driver to null.
 
bool IsSampleRateSupported (int sampleRate)
 Checks if the specified sample rate is supported by the driver.
 
void ShowControlPanel ()
 Shows the control panel.
 
void Play ()
 Starts playing the media if it is not already playing.
 
void Stop ()
 Stops the playback and resets the playback state to Stopped.
 
void Pause ()
 Pauses the playback.
 
void Init (IWaveProvider waveProvider)
 Initializes the recording and playback with the specified waveProvider .
 
void InitRecordAndPlayback (IWaveProvider waveProvider, int recordChannels, int recordOnlySampleRate)
 Initializes the record and playback with the specified wave provider, record channels, and record only sample rate.
 
string AsioInputChannelName (int channel)
 Returns the name of the input channel for the specified index.
 
string AsioOutputChannelName (int channel)
 Returns the name of the output channel based on the provided channel number.
 

Static Public Member Functions

static string[] GetDriverNames ()
 Retrieves the names of the available ASIO drivers.
 
static bool isSupported ()
 Checks if the system supports the operation.
 

Properties

int PlaybackLatency [get]
 Gets the latency (in ms) of the playback driver.
 
bool AutoStop [get, set]
 Automatically stop when the end of the input stream is reached Disable this if auto-stop is causing hanging issues.
 
bool HasReachedEnd [get, private set]
 A flag to let you know that we have reached the end of the input file Useful if AutoStop is set to false You can monitor this yourself and call Stop when it is true.
 
PlaybackState PlaybackState [get]
 Playback State.
 
string DriverName [get]
 Driver Name.
 
int NumberOfOutputChannels [get, private set]
 The number of output channels we are currently using for playback (Must be less than or equal to DriverOutputChannelCount)
 
int NumberOfInputChannels [get, private set]
 The number of input channels we are currently recording from (Must be less than or equal to DriverInputChannelCount)
 
int DriverInputChannelCount [get]
 The maximum number of input channels this ASIO driver supports.
 
int DriverOutputChannelCount [get]
 The maximum number of output channels this ASIO driver supports.
 
int FramesPerBuffer [get]
 The number of samples per channel, per buffer.
 
int ChannelOffset [get, set]
 By default the first channel on the input WaveProvider is sent to the first ASIO output. This option sends it to the specified channel number. Warning: make sure you don't set it higher than the number of available output channels - the number of source channels. n.b. Future NAudio may modify this.
 
int InputChannelOffset [get, set]
 Input channel offset (used when recording), allowing you to choose to record from just one specific input rather than them all.
 
float Volume [get, set]
 Sets the volume (1.0 is unity gain) Not supported for ASIO Out. Set the volume on the input stream instead.
 
WaveFormat OutputWaveFormat [get, private set]
 The WaveFormat this device is using for playback.
 
- Properties inherited from NAudio.Wave.IWavePlayer

Events

EventHandler< StoppedEventArgsPlaybackStopped
 Playback Stopped.
 
EventHandler< AsioAudioAvailableEventArgsAudioAvailable
 When recording, fires whenever recorded audio is available.
 
EventHandler DriverResetRequest
 Occurs when the driver settings are changed by the user, e.g. in the control panel.
 
- 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

 ~AsioOut ()
 Releases unmanaged resources and performs other cleanup operations before the AsioOut is reclaimed by garbage collection.
 
void InitFromName (string driverName)
 Initializes the object using the provided driver name and sets up the extended driver.
 
void OnDriverResetRequest ()
 Raises the DriverResetRequest event.
 
void ReleaseDriver (AsioDriver driver)
 Releases the resources associated with the provided AsioDriver.
 
void driver_BufferUpdate (IntPtr[] inputChannels, IntPtr[] outputChannels)
 Updates the buffer with input and output channels for audio processing.
 
void RaisePlaybackStopped (Exception e)
 Raises the PlaybackStopped event with the specified exception.
 

Private Attributes

AsioDriverExt driver
 
IWaveProvider sourceStream
 
PlaybackState playbackState
 
int nbSamples
 
byte[] waveBuffer
 
AsioSampleConvertor.SampleConvertor convertor
 
string driverName
 
readonly SynchronizationContext syncContext
 
bool isInitialized
 

Detailed Description

ASIO Out Player. New implementation using an internal C# binding.

This implementation is only supporting Short16Bit and Float32Bit formats and is optimized for 2 outputs channels . SampleRate is supported only if AsioDriver is supporting it

This implementation is probably the first AsioDriver binding fully implemented in C#!

Original Contributor: Mark Heath New Contributor to C# binding : Alexandre Mutel - email: alexandre_mutel at yahoo.fr

Constructor & Destructor Documentation

◆ AsioOut() [1/3]

NAudio.Wave.AsioOut.AsioOut ( )
inline

Initializes a new instance of the AsioOut class with the first available ASIO Driver.

◆ AsioOut() [2/3]

NAudio.Wave.AsioOut.AsioOut ( string driverName)
inline

Initializes a new instance of the AsioOut class with the driver name.

Parameters
driverNameName of the device.
Here is the call graph for this function:

◆ AsioOut() [3/3]

NAudio.Wave.AsioOut.AsioOut ( int driverIndex)
inline

Opens an ASIO output device.

Parameters
driverIndexDevice number (zero based)
Here is the call graph for this function:

◆ ~AsioOut()

NAudio.Wave.AsioOut.~AsioOut ( )
inlineprivate

Releases unmanaged resources and performs other cleanup operations before the AsioOut is reclaimed by garbage collection.

Here is the call graph for this function:

Member Function Documentation

◆ AsioInputChannelName()

string NAudio.Wave.AsioOut.AsioInputChannelName ( int channel)
inline

Returns the name of the input channel for the specified index.

Parameters
channelThe index of the input channel.
Returns
The name of the input channel at the specified index. Returns an empty string if the index is greater than the number of input channels supported by the driver.

◆ AsioOutputChannelName()

string NAudio.Wave.AsioOut.AsioOutputChannelName ( int channel)
inline

Returns the name of the output channel based on the provided channel number.

Parameters
channelThe channel number for which the name is to be retrieved.
Returns
The name of the output channel corresponding to the provided channel number, or an empty string if the channel number is greater than the DriverOutputChannelCount.

◆ Dispose()

void NAudio.Wave.AsioOut.Dispose ( )
inline

Releases the resources used by the driver and sets the driver to null.

This method checks if the driver is not null and if the playbackState is not PlaybackState.Stopped. If the conditions are met, it stops the driver and sets the driver to null after releasing the resources. The ResetRequestCallback of the driver is set to null.

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

◆ driver_BufferUpdate()

void NAudio.Wave.AsioOut.driver_BufferUpdate ( IntPtr[] inputChannels,
IntPtr[] outputChannels )
inlineprivate

Updates the buffer with input and output channels for audio processing.

Parameters
inputChannelsAn array of pointers to the input channels.
outputChannelsAn array of pointers to the output channels.

This method updates the buffer with input and output channels for audio processing. It first checks if there are input channels available, and if so, raises the AudioAvailable event with the appropriate arguments. If the event handler writes to the output buffers, the method returns. If there are output channels available, it reads from the source stream into the wave buffer, calls the convertor to process the audio data, and handles end-of-data conditions.

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

◆ GetDriverNames()

static string[] NAudio.Wave.AsioOut.GetDriverNames ( )
inlinestatic

Retrieves the names of the available ASIO drivers.

Returns
An array of strings containing the names of the available ASIO drivers.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Init()

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

Initializes the recording and playback with the specified waveProvider .

Parameters
waveProviderThe wave provider to be initialized.

This method initializes the recording and playback using the specified waveProvider . The recording starts at position 0 and continues indefinitely until stopped.

Implements NAudio.Wave.IWavePlayer.

Here is the call graph for this function:

◆ InitFromName()

void NAudio.Wave.AsioOut.InitFromName ( string driverName)
inlineprivate

Initializes the object using the provided driver name and sets up the extended driver.

Parameters
driverNameThe name of the driver to be initialized.

This method initializes the object with the specified driver name and sets up the extended driver by instantiating it using the basic driver obtained from AsioDriver.GetAsioDriverByName(string). If an exception occurs during the instantiation of the extended driver, the method releases the basic driver and rethrows the exception. The driver.ResetRequestCallback is set to OnDriverResetRequest. The ChannelOffset is set to 0.

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

◆ InitRecordAndPlayback()

void NAudio.Wave.AsioOut.InitRecordAndPlayback ( IWaveProvider waveProvider,
int recordChannels,
int recordOnlySampleRate )
inline

Initializes the record and playback with the specified wave provider, record channels, and record only sample rate.

Parameters
waveProviderThe wave provider to be initialized.
recordChannelsThe number of record channels.
recordOnlySampleRateThe record only sample rate.
Exceptions
InvalidOperationExceptionThrown when attempting to initialize an already initialized instance of AsioOut.
ArgumentExceptionThrown when the sample rate is not supported.

This method initializes the record and playback with the specified wave provider, record channels, and record only sample rate. It sets the desired sample rate based on the wave provider or the record only sample rate. If the wave provider is not null, it sets the source stream, number of output channels, and selects the correct sample convertor based on the ASIO format. It then sets the output wave format based on the ASIO sample type. If the wave provider is null, it sets the number of output channels to 0. It checks if the desired sample rate is supported and sets it if necessary. The method also plugs the callback, fills the buffer, sets the number of input channels, creates buffers, and sets the channel offset. Finally, it creates a buffer big enough to read from the source stream to fill the ASIO buffers if the wave provider is not null.

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

◆ IsSampleRateSupported()

bool NAudio.Wave.AsioOut.IsSampleRateSupported ( int sampleRate)
inline

Checks if the specified sample rate is supported by the driver.

Parameters
sampleRateThe sample rate to be checked.
Returns
True if the sample rate is supported; otherwise, false.
Here is the call graph for this function:

◆ isSupported()

static bool NAudio.Wave.AsioOut.isSupported ( )
inlinestatic

Checks if the system supports the operation.

Returns
True if the system supports the operation; otherwise, false.
Here is the call graph for this function:

◆ OnDriverResetRequest()

void NAudio.Wave.AsioOut.OnDriverResetRequest ( )
inlineprivate

Raises the DriverResetRequest event.

This method raises the DriverResetRequest event, indicating that a reset request has been made for the driver.

Here is the caller graph for this function:

◆ Pause()

void NAudio.Wave.AsioOut.Pause ( )
inline

Pauses the playback.

This method changes the playback state to paused and stops the driver.

Implements NAudio.Wave.IWavePlayer.

Here is the call graph for this function:

◆ Play()

void NAudio.Wave.AsioOut.Play ( )
inline

Starts playing the media if it is not already playing.

This method checks the current playback state and starts playing the media if it is not already in the playing state. If the media is already playing, this method does nothing.

Implements NAudio.Wave.IWavePlayer.

Here is the call graph for this function:

◆ RaisePlaybackStopped()

void NAudio.Wave.AsioOut.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:

◆ ReleaseDriver()

void NAudio.Wave.AsioOut.ReleaseDriver ( AsioDriver driver)
inlineprivate

Releases the resources associated with the provided AsioDriver.

Parameters
driverThe AsioDriver to be released.

This method disposes the buffers associated with the provided driver and releases the COM AsioDriver resources.

Here is the caller graph for this function:

◆ ShowControlPanel()

void NAudio.Wave.AsioOut.ShowControlPanel ( )
inline

Shows the control panel.

This method calls the driver.ShowControlPanel method to display the control panel.

Here is the call graph for this function:

◆ Stop()

void NAudio.Wave.AsioOut.Stop ( )
inline

Stops the playback and resets the playback state to Stopped.

Implements NAudio.Wave.IWavePlayer.

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

Member Data Documentation

◆ convertor

AsioSampleConvertor.SampleConvertor NAudio.Wave.AsioOut.convertor
private

◆ driver

AsioDriverExt NAudio.Wave.AsioOut.driver
private

◆ driverName

string NAudio.Wave.AsioOut.driverName
private

◆ isInitialized

bool NAudio.Wave.AsioOut.isInitialized
private

◆ nbSamples

int NAudio.Wave.AsioOut.nbSamples
private

◆ playbackState

PlaybackState NAudio.Wave.AsioOut.playbackState
private

◆ sourceStream

IWaveProvider NAudio.Wave.AsioOut.sourceStream
private

◆ syncContext

readonly SynchronizationContext NAudio.Wave.AsioOut.syncContext
private

◆ waveBuffer

byte [] NAudio.Wave.AsioOut.waveBuffer
private

Property Documentation

◆ AutoStop

bool NAudio.Wave.AsioOut.AutoStop
getset

Automatically stop when the end of the input stream is reached Disable this if auto-stop is causing hanging issues.

◆ ChannelOffset

int NAudio.Wave.AsioOut.ChannelOffset
getset

By default the first channel on the input WaveProvider is sent to the first ASIO output. This option sends it to the specified channel number. Warning: make sure you don't set it higher than the number of available output channels - the number of source channels. n.b. Future NAudio may modify this.

◆ DriverInputChannelCount

int NAudio.Wave.AsioOut.DriverInputChannelCount
get

The maximum number of input channels this ASIO driver supports.

◆ DriverName

string NAudio.Wave.AsioOut.DriverName
get

Driver Name.

◆ DriverOutputChannelCount

int NAudio.Wave.AsioOut.DriverOutputChannelCount
get

The maximum number of output channels this ASIO driver supports.

◆ FramesPerBuffer

int NAudio.Wave.AsioOut.FramesPerBuffer
get

The number of samples per channel, per buffer.

◆ HasReachedEnd

bool NAudio.Wave.AsioOut.HasReachedEnd
getprivate set

A flag to let you know that we have reached the end of the input file Useful if AutoStop is set to false You can monitor this yourself and call Stop when it is true.

◆ InputChannelOffset

int NAudio.Wave.AsioOut.InputChannelOffset
getset

Input channel offset (used when recording), allowing you to choose to record from just one specific input rather than them all.

◆ NumberOfInputChannels

int NAudio.Wave.AsioOut.NumberOfInputChannels
getprivate set

The number of input channels we are currently recording from (Must be less than or equal to DriverInputChannelCount)

◆ NumberOfOutputChannels

int NAudio.Wave.AsioOut.NumberOfOutputChannels
getprivate set

The number of output channels we are currently using for playback (Must be less than or equal to DriverOutputChannelCount)

◆ OutputWaveFormat

WaveFormat NAudio.Wave.AsioOut.OutputWaveFormat
getprivate set

The WaveFormat this device is using for playback.

Implements NAudio.Wave.IWavePlayer.

◆ PlaybackLatency

int NAudio.Wave.AsioOut.PlaybackLatency
get

Gets the latency (in ms) of the playback driver.

◆ PlaybackState

PlaybackState NAudio.Wave.AsioOut.PlaybackState
get

Playback State.

Implements NAudio.Wave.IWavePlayer.

◆ Volume

float NAudio.Wave.AsioOut.Volume
getset

Sets the volume (1.0 is unity gain) Not supported for ASIO Out. Set the volume on the input stream instead.

Implements NAudio.Wave.IWavePlayer.

Event Documentation

◆ AudioAvailable

EventHandler<AsioAudioAvailableEventArgs> NAudio.Wave.AsioOut.AudioAvailable

When recording, fires whenever recorded audio is available.

◆ DriverResetRequest

EventHandler NAudio.Wave.AsioOut.DriverResetRequest

Occurs when the driver settings are changed by the user, e.g. in the control panel.

◆ PlaybackStopped

EventHandler<StoppedEventArgs> NAudio.Wave.AsioOut.PlaybackStopped

Playback Stopped.


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