From 1fff5cc885d1539bc7075652a31a0dc49ebbc7f3 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Fri, 17 Jul 2009 23:00:22 +0000 Subject: [PATCH] Renamed AudioContext.Default to AudioContext.DefaulDevice. Improved error checking code. --- Source/OpenTK/Audio/AudioContext.cs | 75 ++++++++++++++++------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/Source/OpenTK/Audio/AudioContext.cs b/Source/OpenTK/Audio/AudioContext.cs index efe765c2..3b9ed87f 100644 --- a/Source/OpenTK/Audio/AudioContext.cs +++ b/Source/OpenTK/Audio/AudioContext.cs @@ -270,8 +270,8 @@ namespace OpenTK.Audio } if (device_handle == IntPtr.Zero) { - device_name = AudioContext.Default; - device_handle = Alc.OpenDevice(AudioContext.Default); // try to open named default device + device_name = AudioContext.DefaultDevice; + device_handle = Alc.OpenDevice(AudioContext.DefaultDevice); // try to open named default device } if (device_handle == IntPtr.Zero) { @@ -280,7 +280,7 @@ namespace OpenTK.Audio String.IsNullOrEmpty(device) ? "default" : device)); } - CheckForAlcErrors(); + CheckErrors(); // Build the attribute list List attributes = new List(); @@ -330,7 +330,7 @@ namespace OpenTK.Audio throw new AudioContextException("The audio context could not be created with the specified parameters."); } - CheckForAlcErrors(); + CheckErrors(); // HACK: OpenAL SI on Linux/ALSA crashes on MakeCurrent. This hack avoids calling MakeCurrent when // an old OpenAL version is detect - it may affect outdated OpenAL versions different than OpenAL SI, @@ -338,23 +338,10 @@ namespace OpenTK.Audio if (AudioDeviceEnumerator.AvailablePlaybackDevices.Count > 0) MakeCurrent(); - CheckForAlcErrors(); + CheckErrors(); device_name = Alc.GetString(device_handle, AlcGetString.DeviceSpecifier); - int attribute_count; - Alc.GetInteger(device_handle, AlcGetInteger.AttributesSize, 1, out attribute_count); - if (attribute_count > 0) - { - int[] device_attributes = new int[attribute_count]; - Alc.GetInteger(device_handle, AlcGetInteger.AllAttributes, device_attributes.Length, device_attributes); - foreach (int attr in device_attributes) - { - switch ((AlcContextAttributes)attr) - { - case AlcContextAttributes.Sync: IsSynchronized = true; break; - } - } - } + lock (audio_context_lock) { @@ -365,17 +352,6 @@ namespace OpenTK.Audio #endregion --- Private Methods --- - #region void CheckForAlcErrors() - - void CheckForAlcErrors() - { - AlcError err = Alc.GetError(device_handle); - if (err != AlcError.NoError) - throw new AudioContextException("Device (" + device_handle + ") " + err.ToString()); - } - - #endregion - #region static void MakeCurrent(AudioContext context) /// @@ -443,6 +419,35 @@ namespace OpenTK.Audio #region --- Public Members --- + #region CheckErrors + + /// + /// Checks for ALC error conditions. + /// + /// Raised when an out of memory error is detected. + /// Raised when an invalid value is detected. + /// Raised when an invalid device is detected. + /// Raised when an invalid context is detected. + public void CheckErrors() + { + new AudioDeviceErrorChecker(device_handle).Dispose(); + } + + #endregion + + #region CurrentError + + /// Returns the ALC error code for this device. + public AlcError CurrentError + { + get + { + return Alc.GetError(device_handle); + } + } + + #endregion + #region public void MakeCurrent() /// Makes the AudioContext current in the calling thread. @@ -600,7 +605,7 @@ namespace OpenTK.Audio #endregion - #region public static IList AvailableDevices + #region AvailableDevices /// Returns a list of strings containing all known playback devices. public static IList AvailableDevices { @@ -611,16 +616,18 @@ namespace OpenTK.Audio } #endregion public static IList AvailablePlaybackDevices - #region public static string Default + #region DefaultDevice + /// Returns the name of the device that will be used as playback default. - public static string Default + public static string DefaultDevice { get { return AudioDeviceEnumerator.DefaultPlaybackDevice; } } - #endregion public static string DefaultPlaybackDevice + + #endregion #region public string CurrentDeviceName /// Returns the name of the used device for the current context.