/// <summary> /// Opens a default audio rendering device /// </summary> /// <returns>true on success, false otherwise</returns> public virtual void Initialize() { if (IsOpen) { return; } m_Handle = ALC.OpenDevice(m_Name); if (!IsOpen) { throw new UserFriendlyException(String.Format("Failed to open audio device '{0}'", m_Name), "Failed to initialize audio"); } // ALC.RuntimeImport(m_Handle); // reimport because some functions may be device specific if (!CreateContext()) { Close(); throw new UserFriendlyException(String.Format("Failed to create audio context for device '{0}'", m_Name), "Failed to initialize audio"); } if (!MakeContextCurrent()) { Close(); throw new UserFriendlyException(String.Format("Failed to switch to audio context of device '{0}'", m_Name), "Failed to initialize audio"); } m_Listener = new SoundListener(this); }
public OpenALContext(AudioDevice device) { m_Device = device; m_Handle = ALC.CreateContext(device.Handle); MakeCurrent(); Externals = new OpenALExternals(this); }
public virtual bool MakeCurrent() { if (m_Handle == IntPtr.Zero) { return(false); } return(ALC.MakeContextCurrent(m_Handle)); }
public virtual void Close() { if (m_Handle != IntPtr.Zero) { CloseContext(); ALC.CloseDevice(m_Handle); m_Handle = IntPtr.Zero; m_Name = ""; } }
public virtual void Dispose() { if (m_Handle != IntPtr.Zero) { ALC.MakeContextCurrent(IntPtr.Zero); ALC.DestroyContext(m_Handle); m_Handle = IntPtr.Zero; } m_Device = null; }
public static string GetDefaultDevice() { if (ALC.IsExtensionPresent("ALC_ENUMERATE_ALL_EXT")) { return(ALC.GetString(AlcStringName.DefaultAllDevicesSpecifier)); } if (ALC.IsExtensionPresent("ALC_ENUMERATION_EXT")) { return(ALC.GetString(AlcStringName.DefaultDeviceSpecifier)); } return(""); }
public static string[] GetAvailableDevices() { if (ALC.IsExtensionPresent("ALC_ENUMERATE_ALL_EXT")) { return(ALC.GetStrings(AlcStringArrayName.AllDevicesSpecifier).ToArray()); } if (ALC.IsExtensionPresent("ALC_ENUMERATION_EXT")) { return(ALC.GetStrings(AlcStringArrayName.DeviceSpecifier).ToArray()); } return(new string[] { "" }); }