mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-25 06:45:31 +00:00
* Audio/AudioContext.cs: Now initializes EFX slots to maximum number supported by hardware. Fixed a potential crash bug during context creation (attribute array should be zero-terminated).
This commit is contained in:
parent
7c1d479609
commit
3d9489bc3a
|
@ -63,15 +63,11 @@ namespace OpenTK.Audio
|
||||||
|
|
||||||
/// <summary>Constructs a new AudioContext, using the default audio device.</summary>
|
/// <summary>Constructs a new AudioContext, using the default audio device.</summary>
|
||||||
/// <exception cref="NotSupportedException">Occurs when no audio devices are available.</exception>
|
/// <exception cref="NotSupportedException">Occurs when no audio devices are available.</exception>
|
||||||
public AudioContext()// : this(available_devices.Count > 0 ? available_devices[0] : null, 0, 0, false, 0) { }
|
public AudioContext()
|
||||||
{
|
: this(null, 0, 0, false, true) { }
|
||||||
if (!openal_supported)
|
|
||||||
throw new DllNotFoundException("openal32.dll");
|
|
||||||
CreateContext(null, 0, 0, false, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
#if false
|
|
||||||
#region public AudioContext(string device)
|
#region public AudioContext(string device)
|
||||||
|
|
||||||
/// <summary>Constructs a new AudioContext, using the specified audio device.</summary>
|
/// <summary>Constructs a new AudioContext, using the specified audio device.</summary>
|
||||||
|
@ -80,7 +76,7 @@ namespace OpenTK.Audio
|
||||||
/// Use AudioContext.AvailableDevices to obtain a list of all available audio devices.
|
/// Use AudioContext.AvailableDevices to obtain a list of all available audio devices.
|
||||||
/// devices.
|
/// devices.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public AudioContext(string device) : this(device, 0, 0, false, 0) { }
|
public AudioContext(string device) : this(device, 0, 0, false, true) { }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -94,7 +90,7 @@ namespace OpenTK.Audio
|
||||||
/// devices.
|
/// devices.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <see cref="AudioContext(string device, int freq, int refresh, bool sync, int maxEfxSends)"/>
|
/// <see cref="AudioContext(string device, int freq, int refresh, bool sync, int maxEfxSends)"/>
|
||||||
public AudioContext(string device, int freq) : this(device, freq, 0, false, 0) { }
|
public AudioContext(string device, int freq) : this(device, freq, 0, false, true) { }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -110,7 +106,7 @@ namespace OpenTK.Audio
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <see cref="AudioContext(string device, int freq, int refresh, bool sync, int maxEfxSends)"/>
|
/// <see cref="AudioContext(string device, int freq, int refresh, bool sync, int maxEfxSends)"/>
|
||||||
public AudioContext(string device, int freq, int refresh)
|
public AudioContext(string device, int freq, int refresh)
|
||||||
: this(device, freq, refresh, false, 0) { }
|
: this(device, freq, refresh, false, true) { }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -127,7 +123,7 @@ namespace OpenTK.Audio
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <see cref="AudioContext(string device, int freq, int refresh, bool sync, int maxEfxSends)"/>
|
/// <see cref="AudioContext(string device, int freq, int refresh, bool sync, int maxEfxSends)"/>
|
||||||
public AudioContext(string device, int freq, int refresh, bool sync)
|
public AudioContext(string device, int freq, int refresh, bool sync)
|
||||||
: this(available_devices[0], freq, refresh, sync, 0) { }
|
: this(available_devices[0], freq, refresh, sync, true) { }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -138,7 +134,7 @@ namespace OpenTK.Audio
|
||||||
/// <param name="freq">Frequency for mixing output buffer, in units of Hz. Pass 0 for driver default.</param>
|
/// <param name="freq">Frequency for mixing output buffer, in units of Hz. Pass 0 for driver default.</param>
|
||||||
/// <param name="refresh">Refresh intervals, in units of Hz. Pass 0 for driver default.</param>
|
/// <param name="refresh">Refresh intervals, in units of Hz. Pass 0 for driver default.</param>
|
||||||
/// <param name="sync">Flag, indicating a synchronous context.</param>
|
/// <param name="sync">Flag, indicating a synchronous context.</param>
|
||||||
/// <param name="maxSends">Number of auxilliary send slots for the EFX extensions. Can be 0 (use driver default) or higher.</param>
|
/// <param name="enableEfx">Indicates whether the EFX extension should be initialized, if present.</param>
|
||||||
/// <exception cref="ArgumentNullException">Occurs when the device string is invalid.</exception>
|
/// <exception cref="ArgumentNullException">Occurs when the device string is invalid.</exception>
|
||||||
/// <exception cref="ArgumentOutOfRangeException">Occurs when a specified parameter is invalid.</exception>
|
/// <exception cref="ArgumentOutOfRangeException">Occurs when a specified parameter is invalid.</exception>
|
||||||
/// <exception cref="InvalidAudioDeviceException">
|
/// <exception cref="InvalidAudioDeviceException">
|
||||||
|
@ -158,13 +154,13 @@ namespace OpenTK.Audio
|
||||||
/// Values higher than supported will be clamped by the driver.
|
/// Values higher than supported will be clamped by the driver.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public AudioContext(string device, int freq, int refresh, bool sync, int maxSends)
|
public AudioContext(string device, int freq, int refresh, bool sync, bool enableEfx)
|
||||||
{
|
{
|
||||||
CreateContext(device, freq, refresh, sync, maxSends);
|
CreateContext(device, freq, refresh, sync, enableEfx);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
#endif
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region --- Private Methods ---
|
#region --- Private Methods ---
|
||||||
|
@ -219,7 +215,7 @@ namespace OpenTK.Audio
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region void CreateContext(string device)
|
#region CreateContext
|
||||||
|
|
||||||
/// <private />
|
/// <private />
|
||||||
/// <summary>Creates the audio context using the specified device.</summary>
|
/// <summary>Creates the audio context using the specified device.</summary>
|
||||||
|
@ -227,7 +223,7 @@ namespace OpenTK.Audio
|
||||||
/// <param name="freq">Frequency for mixing output buffer, in units of Hz. Pass 0 for driver default.</param>
|
/// <param name="freq">Frequency for mixing output buffer, in units of Hz. Pass 0 for driver default.</param>
|
||||||
/// <param name="refresh">Refresh intervals, in units of Hz. Pass 0 for driver default.</param>
|
/// <param name="refresh">Refresh intervals, in units of Hz. Pass 0 for driver default.</param>
|
||||||
/// <param name="sync">Flag, indicating a synchronous context.</param>
|
/// <param name="sync">Flag, indicating a synchronous context.</param>
|
||||||
/// <param name="maxEfxSends">Number of auxilliary send slots for the EFX extensions. Can be 0 (use driver default) or higher.</param>
|
/// <param name="enableEfx">Indicates whether the EFX extension should be initialized, if present.</param>
|
||||||
/// /// <exception cref="ArgumentOutOfRangeException">Occurs when a specified parameter is invalid.</exception>
|
/// /// <exception cref="ArgumentOutOfRangeException">Occurs when a specified parameter is invalid.</exception>
|
||||||
/// <exception cref="AudioDeviceException">
|
/// <exception cref="AudioDeviceException">
|
||||||
/// Occurs when the specified device is not available, or is in use by another program.
|
/// Occurs when the specified device is not available, or is in use by another program.
|
||||||
|
@ -246,14 +242,16 @@ namespace OpenTK.Audio
|
||||||
/// Values higher than supported will be clamped by the driver.
|
/// Values higher than supported will be clamped by the driver.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
void CreateContext(string device, int freq, int refresh, bool sync, int maxEfxSends)
|
void CreateContext(string device, int freq, int refresh, bool sync, bool enableEfx)
|
||||||
{
|
{
|
||||||
|
if (!openal_supported)
|
||||||
|
throw new DllNotFoundException("openal32.dll");
|
||||||
|
|
||||||
if (version == Version.OpenAL11 && available_devices.Count == 0) // Version.OpenAL10 does not support device enumeration.
|
if (version == Version.OpenAL11 && available_devices.Count == 0) // Version.OpenAL10 does not support device enumeration.
|
||||||
throw new NotSupportedException("No audio hardware is available.");
|
throw new NotSupportedException("No audio hardware is available.");
|
||||||
if (context_exists) throw new NotSupportedException("Multiple AudioContexts are not supported.");
|
if (context_exists) throw new NotSupportedException("Multiple AudioContexts are not supported.");
|
||||||
if (freq < 0) throw new ArgumentOutOfRangeException("freq", freq, "Should be greater than zero.");
|
if (freq < 0) throw new ArgumentOutOfRangeException("freq", freq, "Should be greater than zero.");
|
||||||
if (refresh < 0) throw new ArgumentOutOfRangeException("refresh", refresh, "Should be greater than zero.");
|
if (refresh < 0) throw new ArgumentOutOfRangeException("refresh", refresh, "Should be greater than zero.");
|
||||||
if (maxEfxSends < 0) throw new ArgumentOutOfRangeException("maxEfxSends", maxEfxSends, "Should be greater than zero.");
|
|
||||||
|
|
||||||
if (!String.IsNullOrEmpty(device))
|
if (!String.IsNullOrEmpty(device))
|
||||||
device_handle = Alc.OpenDevice(device);
|
device_handle = Alc.OpenDevice(device);
|
||||||
|
@ -289,13 +287,14 @@ namespace OpenTK.Audio
|
||||||
attributes.Add((int)AlcContextAttributes.Frequency);
|
attributes.Add((int)AlcContextAttributes.Frequency);
|
||||||
attributes.Add(sync ? 1 : 0);
|
attributes.Add(sync ? 1 : 0);
|
||||||
|
|
||||||
if (maxEfxSends > 0)
|
if (enableEfx && Alc.IsExtensionPresent(device_handle, "ALC_EXT_EFX"))
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
int num_slots;
|
||||||
//if (Alc.IsExtensionPresent(device_handle, "ALC_EXT_EFX"))
|
Alc.GetInteger(device_handle, AlcGetInteger.EfxMaxAuxiliarySends, 1, out num_slots);
|
||||||
//attributes.Add((int)AlcContextAttributes.MaxAuxilliarySends);
|
attributes.Add((int)AlcContextAttributes.EfxMaxAuxiliarySends);
|
||||||
//attributes.Add(maxEfxSends);
|
attributes.Add(num_slots);
|
||||||
}
|
}
|
||||||
|
attributes.Add(0);
|
||||||
|
|
||||||
context_handle = Alc.CreateContext(device_handle, attributes.ToArray());
|
context_handle = Alc.CreateContext(device_handle, attributes.ToArray());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue