void Dispose(bool manual) { if (!disposed) { if (this.IsCurrent) { this.IsCurrent = false; } if (context_handle != ContextHandle.Zero) { available_contexts.Remove(context_handle); Alc.DestroyContext(context_handle); } if (device_handle != IntPtr.Zero) { Alc.CloseDevice(device_handle); } if (manual) { } disposed = true; } }
private void Dispose(bool manual) { if (this.disposed) { return; } if (this.IsCurrent) { this.IsCurrent = false; } if (this.context_handle != ContextHandle.Zero) { AudioContext.available_contexts.Remove(this.context_handle); Alc.DestroyContext(this.context_handle); } if (this.device_handle != IntPtr.Zero) { Alc.CloseDevice(this.device_handle); } int num = manual ? 1 : 0; this.disposed = true; }
static AudioDeviceEnumerator() { IntPtr device = IntPtr.Zero; ContextHandle context = ContextHandle.Zero; try { device = Alc.OpenDevice((string)null); int num1 = (int)Alc.GetError(device); context = Alc.CreateContext(device, (int[])null); int num2 = (int)Alc.GetError(device); bool flag = Alc.MakeContextCurrent(context); AlcError error1 = Alc.GetError(device); if (!flag) { throw new AudioContextException("Failed to create dummy Context. Device (" + device.ToString() + ") Context (" + context.Handle.ToString() + ") MakeContextCurrent " + (flag ? "succeeded" : "failed") + ", Alc Error (" + ((object)error1).ToString() + ") " + Alc.GetString(IntPtr.Zero, (AlcGetString)error1)); } else { if (Alc.IsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATION_EXT")) { AudioDeviceEnumerator.version = AudioDeviceEnumerator.AlcVersion.Alc1_1; if (Alc.IsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATE_ALL_EXT")) { AudioDeviceEnumerator.available_playback_devices.AddRange((IEnumerable <string>)Alc.GetString(IntPtr.Zero, AlcGetStringList.AllDevicesSpecifier)); AudioDeviceEnumerator.default_playback_device = Alc.GetString(IntPtr.Zero, AlcGetString.DefaultAllDevicesSpecifier); } else { AudioDeviceEnumerator.available_playback_devices.AddRange((IEnumerable <string>)Alc.GetString(IntPtr.Zero, AlcGetStringList.DeviceSpecifier)); AudioDeviceEnumerator.default_playback_device = Alc.GetString(IntPtr.Zero, AlcGetString.DefaultDeviceSpecifier); } } else { AudioDeviceEnumerator.version = AudioDeviceEnumerator.AlcVersion.Alc1_0; } AlcError error2 = Alc.GetError(device); if (error2 != AlcError.NoError) { throw new AudioContextException("Alc Error occured when querying available playback devices. " + ((object)error2).ToString()); } if (AudioDeviceEnumerator.version == AudioDeviceEnumerator.AlcVersion.Alc1_1 && Alc.IsExtensionPresent(IntPtr.Zero, "ALC_EXT_CAPTURE")) { AudioDeviceEnumerator.available_recording_devices.AddRange((IEnumerable <string>)Alc.GetString(IntPtr.Zero, AlcGetStringList.CaptureDeviceSpecifier)); AudioDeviceEnumerator.default_recording_device = Alc.GetString(IntPtr.Zero, AlcGetString.CaptureDefaultDeviceSpecifier); } AlcError error3 = Alc.GetError(device); if (error3 != AlcError.NoError) { throw new AudioContextException("Alc Error occured when querying available recording devices. " + ((object)error3).ToString()); } } } catch (DllNotFoundException ex) { Trace.WriteLine(ex.ToString()); AudioDeviceEnumerator.openal_supported = false; } catch (AudioContextException ex) { Trace.WriteLine(ex.ToString()); AudioDeviceEnumerator.lastError = ex.ToString(); AudioDeviceEnumerator.openal_supported = false; } finally { Alc.MakeContextCurrent(ContextHandle.Zero); if (context != ContextHandle.Zero && context.Handle != IntPtr.Zero) { Alc.DestroyContext(context); } if (device != IntPtr.Zero) { Alc.CloseDevice(device); } } }
// Loads all available audio devices into the available_*_devices lists. static AudioDeviceEnumerator() { IntPtr dummy_device = IntPtr.Zero; ContextHandle dummy_context = ContextHandle.Zero; try { Debug.WriteLine("Enumerating audio devices."); Debug.Indent(); // need a dummy context for correct results dummy_device = Alc.OpenDevice(null); dummy_context = Alc.CreateContext(dummy_device, (int[])null); bool dummy_success = Alc.MakeContextCurrent(dummy_context); AlcError dummy_error = Alc.GetError(dummy_device); if (!dummy_success || dummy_error != AlcError.NoError) { throw new AudioContextException("Failed to create dummy Context. Device (" + dummy_device.ToString() + ") Context (" + dummy_context.Handle.ToString() + ") MakeContextCurrent " + (dummy_success ? "succeeded" : "failed") + ", Alc Error (" + dummy_error.ToString() + ") " + Alc.GetString(IntPtr.Zero, (AlcGetString)dummy_error)); } // Get a list of all known playback devices, using best extension available if (Alc.IsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATION_EXT")) { version = AlcVersion.Alc1_1; if (Alc.IsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATE_ALL_EXT")) { available_playback_devices.AddRange(Alc.GetString(IntPtr.Zero, AlcGetStringList.AllDevicesSpecifier)); default_playback_device = Alc.GetString(IntPtr.Zero, AlcGetString.DefaultAllDevicesSpecifier); } else { available_playback_devices.AddRange(Alc.GetString(IntPtr.Zero, AlcGetStringList.DeviceSpecifier)); default_playback_device = Alc.GetString(IntPtr.Zero, AlcGetString.DefaultDeviceSpecifier); } } else { version = AlcVersion.Alc1_0; Debug.Print("Device enumeration extension not available. Failed to enumerate playback devices."); } AlcError playback_err = Alc.GetError(dummy_device); if (playback_err != AlcError.NoError) { throw new AudioContextException("Alc Error occured when querying available playback devices. " + playback_err.ToString()); } // Get a list of all known recording devices, at least ALC_ENUMERATION_EXT is needed too if (version == AlcVersion.Alc1_1 && Alc.IsExtensionPresent(IntPtr.Zero, "ALC_EXT_CAPTURE")) { available_recording_devices.AddRange(Alc.GetString(IntPtr.Zero, AlcGetStringList.CaptureDeviceSpecifier)); default_recording_device = Alc.GetString(IntPtr.Zero, AlcGetString.CaptureDefaultDeviceSpecifier); } else { Debug.Print("Capture extension not available. Failed to enumerate recording devices."); } AlcError record_err = Alc.GetError(dummy_device); if (record_err != AlcError.NoError) { throw new AudioContextException("Alc Error occured when querying available recording devices. " + record_err.ToString()); } #if DEBUG Debug.WriteLine("Found playback devices:"); foreach (string s in available_playback_devices) { Debug.WriteLine(s); } Debug.WriteLine("Default playback device: " + default_playback_device); Debug.WriteLine("Found recording devices:"); foreach (string s in available_recording_devices) { Debug.WriteLine(s); } Debug.WriteLine("Default recording device: " + default_recording_device); #endif } catch (DllNotFoundException e) { Trace.WriteLine(e.ToString()); openal_supported = false; } catch (AudioContextException ace) { Trace.WriteLine(ace.ToString()); openal_supported = false; } finally { Debug.Unindent(); if (openal_supported) { try { // clean up the dummy context Alc.MakeContextCurrent(ContextHandle.Zero); if (dummy_context != ContextHandle.Zero && dummy_context.Handle != IntPtr.Zero) { Alc.DestroyContext(dummy_context); } if (dummy_device != IntPtr.Zero) { Alc.CloseDevice(dummy_device); } } catch { openal_supported = false; } } } }