From 3d9489bc3adff46d8998edcebbab9f35f795eefd Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Fri, 13 Mar 2009 00:01:17 +0000 Subject: [PATCH] * 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). --- Source/OpenTK/Audio/AudioContext.cs | 47 ++++++++++++++--------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/Source/OpenTK/Audio/AudioContext.cs b/Source/OpenTK/Audio/AudioContext.cs index af74c86c..cbb97761 100644 --- a/Source/OpenTK/Audio/AudioContext.cs +++ b/Source/OpenTK/Audio/AudioContext.cs @@ -63,15 +63,11 @@ namespace OpenTK.Audio /// Constructs a new AudioContext, using the default audio device. /// Occurs when no audio devices are available. - 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) /// Constructs a new AudioContext, using the specified audio device. @@ -80,7 +76,7 @@ namespace OpenTK.Audio /// Use AudioContext.AvailableDevices to obtain a list of all available audio devices. /// devices. /// - 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. /// /// - 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 /// /// 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 /// /// 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 /// Frequency for mixing output buffer, in units of Hz. Pass 0 for driver default. /// Refresh intervals, in units of Hz. Pass 0 for driver default. /// Flag, indicating a synchronous context. - /// Number of auxilliary send slots for the EFX extensions. Can be 0 (use driver default) or higher. + /// Indicates whether the EFX extension should be initialized, if present. /// Occurs when the device string is invalid. /// Occurs when a specified parameter is invalid. /// @@ -158,13 +154,13 @@ namespace OpenTK.Audio /// Values higher than supported will be clamped by the driver. /// /// - 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 /// /// Creates the audio context using the specified device. @@ -227,7 +223,7 @@ namespace OpenTK.Audio /// Frequency for mixing output buffer, in units of Hz. Pass 0 for driver default. /// Refresh intervals, in units of Hz. Pass 0 for driver default. /// Flag, indicating a synchronous context. - /// Number of auxilliary send slots for the EFX extensions. Can be 0 (use driver default) or higher. + /// Indicates whether the EFX extension should be initialized, if present. /// /// Occurs when a specified parameter is invalid. /// /// 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. /// /// - 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());