* 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:
the_fiddler 2009-03-13 00:01:17 +00:00
parent b423b27d15
commit a6f9c2c428

View file

@ -63,15 +63,11 @@ namespace OpenTK.Audio
/// <summary>Constructs a new AudioContext, using the default audio device.</summary>
/// <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) { }
{
if (!openal_supported)
throw new DllNotFoundException("openal32.dll");
CreateContext(null, 0, 0, false, 0);
}
public AudioContext()
: this(null, 0, 0, false, true) { }
#endregion
#if false
#region public AudioContext(string device)
/// <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.
/// devices.
/// </remarks>
public AudioContext(string device) : this(device, 0, 0, false, 0) { }
public AudioContext(string device) : this(device, 0, 0, false, true) { }
#endregion
@ -94,7 +90,7 @@ namespace OpenTK.Audio
/// devices.
/// </remarks>
/// <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
@ -110,7 +106,7 @@ namespace OpenTK.Audio
/// </remarks>
/// <see cref="AudioContext(string device, int freq, int refresh, bool sync, int maxEfxSends)"/>
public AudioContext(string device, int freq, int refresh)
: this(device, freq, refresh, false, 0) { }
: this(device, freq, refresh, false, true) { }
#endregion
@ -127,7 +123,7 @@ namespace OpenTK.Audio
/// </remarks>
/// <see cref="AudioContext(string device, int freq, int refresh, bool sync, int maxEfxSends)"/>
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
@ -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="refresh">Refresh intervals, in units of Hz. Pass 0 for driver default.</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="ArgumentOutOfRangeException">Occurs when a specified parameter is invalid.</exception>
/// <exception cref="InvalidAudioDeviceException">
@ -158,13 +154,13 @@ namespace OpenTK.Audio
/// Values higher than supported will be clamped by the driver.
/// </para>
/// </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
#endif
#endregion
#region --- Private Methods ---
@ -219,7 +215,7 @@ namespace OpenTK.Audio
#endregion
#region void CreateContext(string device)
#region CreateContext
/// <private />
/// <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="refresh">Refresh intervals, in units of Hz. Pass 0 for driver default.</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="AudioDeviceException">
/// 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.
/// </para>
/// </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.
throw new NotSupportedException("No audio hardware is available.");
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 (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))
device_handle = Alc.OpenDevice(device);
@ -289,13 +287,14 @@ namespace OpenTK.Audio
attributes.Add((int)AlcContextAttributes.Frequency);
attributes.Add(sync ? 1 : 0);
if (maxEfxSends > 0)
if (enableEfx && Alc.IsExtensionPresent(device_handle, "ALC_EXT_EFX"))
{
throw new NotImplementedException();
//if (Alc.IsExtensionPresent(device_handle, "ALC_EXT_EFX"))
//attributes.Add((int)AlcContextAttributes.MaxAuxilliarySends);
//attributes.Add(maxEfxSends);
int num_slots;
Alc.GetInteger(device_handle, AlcGetInteger.EfxMaxAuxiliarySends, 1, out num_slots);
attributes.Add((int)AlcContextAttributes.EfxMaxAuxiliarySends);
attributes.Add(num_slots);
}
attributes.Add(0);
context_handle = Alc.CreateContext(device_handle, attributes.ToArray());