Class AudioContext
Provides methods to instantiate, use and destroy an audio context for playback. Static methods are provided to list available devices known by the driver.
Implements
Inherited Members
Namespace: OpenTK.Audio
Assembly: OpenTK.dll
Syntax
public sealed class AudioContext : IDisposable
Constructors
AudioContext()
Constructs a new AudioContext, using the default audio device.
Declaration
public AudioContext()
AudioContext(String)
Constructs a new AudioContext instance.
Declaration
public AudioContext(string device)
Parameters
Type | Name | Description |
---|---|---|
String | device | The device name that will host this instance. |
AudioContext(String, Int32)
Constructs a new AudioContext, using the specified audio device and device parameters.
Declaration
public AudioContext(string device, int freq)
Parameters
Type | Name | Description |
---|---|---|
String | device | The name of the audio device to use. |
Int32 | freq | Frequency for mixing output buffer, in units of Hz. Pass 0 for driver default. |
Remarks
Use AudioContext.AvailableDevices to obtain a list of all available audio devices. devices.
AudioContext(String, Int32, Int32)
Constructs a new AudioContext, using the specified audio device and device parameters.
Declaration
public AudioContext(string device, int freq, int refresh)
Parameters
Type | Name | Description |
---|---|---|
String | device | The name of the audio device to use. |
Int32 | freq | Frequency for mixing output buffer, in units of Hz. Pass 0 for driver default. |
Int32 | refresh | Refresh intervals, in units of Hz. Pass 0 for driver default. |
Remarks
Use AudioContext.AvailableDevices to obtain a list of all available audio devices. devices.
AudioContext(String, Int32, Int32, Boolean)
Constructs a new AudioContext, using the specified audio device and device parameters.
Declaration
public AudioContext(string device, int freq, int refresh, bool sync)
Parameters
Type | Name | Description |
---|---|---|
String | device | The name of the audio device to use. |
Int32 | freq | Frequency for mixing output buffer, in units of Hz. Pass 0 for driver default. |
Int32 | refresh | Refresh intervals, in units of Hz. Pass 0 for driver default. |
Boolean | sync | Flag, indicating a synchronous context. |
Remarks
Use AudioContext.AvailableDevices to obtain a list of all available audio devices. devices.
AudioContext(String, Int32, Int32, Boolean, Boolean)
Creates the audio context using the specified device and device parameters.
Declaration
public AudioContext(string device, int freq, int refresh, bool sync, bool enableEfx)
Parameters
Type | Name | Description |
---|---|---|
String | device | The device descriptor obtained through AudioContext.AvailableDevices. |
Int32 | freq | Frequency for mixing output buffer, in units of Hz. Pass 0 for driver default. |
Int32 | refresh | Refresh intervals, in units of Hz. Pass 0 for driver default. |
Boolean | sync | Flag, indicating a synchronous context. |
Boolean | enableEfx | Indicates whether the EFX extension should be initialized, if present. |
Remarks
For maximum compatibility, you are strongly recommended to use the default constructor.
Multiple AudioContexts are not supported at this point.
The number of auxilliary EFX sends depends on the audio hardware and drivers. Most Realtek devices, as well as the Creative SB Live!, support 1 auxilliary send. Creative's Audigy and X-Fi series support 4 sends. Values higher than supported will be clamped by the driver.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Occurs when the device string is invalid. |
ArgumentOutOfRangeException | Occurs when a specified parameter is invalid. |
AudioDeviceException | Occurs when the specified device is not available, or is in use by another program. |
AudioContextException | Occurs when an audio context could not be created with the specified parameters. |
NotSupportedException | Occurs when an AudioContext already exists. |
AudioContext(String, Int32, Int32, Boolean, Boolean, AudioContext.MaxAuxiliarySends)
Creates the audio context using the specified device and device parameters.
Declaration
public AudioContext(string device, int freq, int refresh, bool sync, bool enableEfx, AudioContext.MaxAuxiliarySends efxMaxAuxSends)
Parameters
Type | Name | Description |
---|---|---|
String | device | The device descriptor obtained through AudioContext.AvailableDevices. |
Int32 | freq | Frequency for mixing output buffer, in units of Hz. Pass 0 for driver default. |
Int32 | refresh | Refresh intervals, in units of Hz. Pass 0 for driver default. |
Boolean | sync | Flag, indicating a synchronous context. |
Boolean | enableEfx | Indicates whether the EFX extension should be initialized, if present. |
AudioContext.MaxAuxiliarySends | efxMaxAuxSends | Requires EFX enabled. The number of desired Auxiliary Sends per source. |
Remarks
For maximum compatibility, you are strongly recommended to use the default constructor.
Multiple AudioContexts are not supported at this point.
The number of auxilliary EFX sends depends on the audio hardware and drivers. Most Realtek devices, as well as the Creative SB Live!, support 1 auxilliary send. Creative's Audigy and X-Fi series support 4 sends. Values higher than supported will be clamped by the driver.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Occurs when the device string is invalid. |
ArgumentOutOfRangeException | Occurs when a specified parameter is invalid. |
AudioDeviceException | Occurs when the specified device is not available, or is in use by another program. |
AudioContextException | Occurs when an audio context could not be created with the specified parameters. |
NotSupportedException | Occurs when an AudioContext already exists. |
Properties
AvailableDevices
Returns a list of strings containing all known playback devices.
Declaration
public static IList<string> AvailableDevices { get; }
Property Value
Type | Description |
---|---|
IList<String> |
CurrentContext
Gets the OpenTK.Audio.AudioContext which is current in the application.
Declaration
public static AudioContext CurrentContext { get; }
Property Value
Type | Description |
---|---|
AudioContext |
Remarks
Only one AudioContext can be current in the application at any time, regardless of the number of threads.
CurrentDevice
Gets a System.String with the name of the device used in this context.
Declaration
public string CurrentDevice { get; }
Property Value
Type | Description |
---|---|
String |
CurrentError
Returns the ALC error code for this instance.
Declaration
public AlcError CurrentError { get; }
Property Value
Type | Description |
---|---|
AlcError |
DefaultDevice
Returns the name of the device that will be used as playback default.
Declaration
public static string DefaultDevice { get; }
Property Value
Type | Description |
---|---|
String |
IsProcessing
Gets a System.Boolean indicating whether the AudioContext is currently processing audio events.
Declaration
public bool IsProcessing { get; }
Property Value
Type | Description |
---|---|
Boolean |
See Also
IsSynchronized
Gets a System.Boolean indicating whether the AudioContext is synchronized.
Declaration
public bool IsSynchronized { get; }
Property Value
Type | Description |
---|---|
Boolean |
See Also
Methods
CheckErrors()
Checks for ALC error conditions.
Declaration
public void CheckErrors()
Exceptions
Type | Condition |
---|---|
OutOfMemoryException | Raised when an out of memory error is detected. |
AudioValueException | Raised when an invalid value is detected. |
AudioDeviceException | Raised when an invalid device is detected. |
AudioContextException | Raised when an invalid context is detected. |
Dispose()
Disposes of the AudioContext, cleaning up all resources consumed by it.
Declaration
public void Dispose()
Equals(Object)
Compares this instance with another.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj | The instance to compare to. |
Returns
Type | Description |
---|---|
Boolean | True, if obj refers to this instance; false otherwise. |
Overrides
Finalize()
Finalizes this instance.
Declaration
protected void Finalize()
GetHashCode()
Calculates the hash code for this instance.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 |
Overrides
MakeCurrent()
Makes the AudioContext current in the calling thread.
Declaration
public void MakeCurrent()
Remarks
Only one AudioContext can be current in the application at any time, regardless of the number of threads.
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | Occurs if this function is called after the AudioContext has been disposed. |
AudioContextException | Occurs when the AudioContext could not be made current. |
Process()
Processes queued audio events.
Declaration
public void Process()
Remarks
If AudioContext.IsSynchronized is true, this function will resume the internal audio processing thread. If AudioContext.IsSynchronized is false, you will need to call this function multiple times per second to process audio events.
In some implementations this function may have no effect.
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | Occurs when this function is called after the AudioContext had been disposed. |
See Also
SupportsExtension(String)
Checks whether the specified OpenAL extension is supported.
Declaration
public bool SupportsExtension(string extension)
Parameters
Type | Name | Description |
---|---|---|
String | extension | The name of the extension to check (e.g. "ALC_EXT_EFX"). |
Returns
Type | Description |
---|---|
Boolean | true if the extension is supported; false otherwise. |
Suspend()
Suspends processing of audio events.
Declaration
public void Suspend()
Remarks
To avoid audio artifacts when calling this function, set audio gain to zero before suspending an AudioContext.
In some implementations, it can be faster to suspend processing before changing AudioContext state.
In some implementations this function may have no effect.
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | Occurs when this function is called after the AudioContext had been disposed. |
See Also
ToString()
Returns a String that desrcibes this instance.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | A String that desrcibes this instance. |