From b977db6a5e86e6d367c94f58ef0871b97faca03d Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Sun, 13 Apr 2008 19:46:42 +0000 Subject: [PATCH] Fixed a bug that would cause context creation to fail under OpenAL SI (0.0.6-0.0.8) on Linux. --- Source/OpenTK/Audio/AudioContext.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Source/OpenTK/Audio/AudioContext.cs b/Source/OpenTK/Audio/AudioContext.cs index 487254c9..b35962f8 100644 --- a/Source/OpenTK/Audio/AudioContext.cs +++ b/Source/OpenTK/Audio/AudioContext.cs @@ -25,12 +25,20 @@ namespace OpenTK.Audio bool disposed; bool is_processing; ContextHandle device_handle, context_handle; + bool context_exists; + string device_name; static object audio_context_lock = new object(); static List available_devices = new List(); static Dictionary available_contexts = new Dictionary(); static bool openal_supported = true; - bool context_exists; + static Version version; + + private enum Version + { + OpenAL10, + OpenAL11 + } #endregion @@ -182,9 +190,15 @@ namespace OpenTK.Audio Debug.Indent(); if (Alc.IsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATION_EXT")) + { + version = Version.OpenAL11; available_devices.AddRange(Alc.GetString(IntPtr.Zero, AlcGetStringList.DeviceSpecifier)); + } else + { + version = Version.OpenAL10; Debug.Print("Device enumeration extension not available. Failed to enumerate devices."); + } foreach (string s in available_devices) Debug.WriteLine(s); @@ -233,7 +247,8 @@ namespace OpenTK.Audio /// void CreateContext(string device, int freq, int refresh, bool sync, int maxEfxSends) { - if (available_devices.Count == 0) throw new NotSupportedException("No audio hardware is available."); + 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.");