コード例 #1
0
        /// <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);
        }
コード例 #2
0
 public OpenALContext(AudioDevice device)
 {
     m_Device = device;
     m_Handle = ALC.CreateContext(device.Handle);
     MakeCurrent();
     Externals = new OpenALExternals(this);
 }
コード例 #3
0
 public virtual bool MakeCurrent()
 {
     if (m_Handle == IntPtr.Zero)
     {
         return(false);
     }
     return(ALC.MakeContextCurrent(m_Handle));
 }
コード例 #4
0
 public virtual void Close()
 {
     if (m_Handle != IntPtr.Zero)
     {
         CloseContext();
         ALC.CloseDevice(m_Handle);
         m_Handle = IntPtr.Zero;
         m_Name   = "";
     }
 }
コード例 #5
0
 public virtual void Dispose()
 {
     if (m_Handle != IntPtr.Zero)
     {
         ALC.MakeContextCurrent(IntPtr.Zero);
         ALC.DestroyContext(m_Handle);
         m_Handle = IntPtr.Zero;
     }
     m_Device = null;
 }
コード例 #6
0
 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("");
 }
コード例 #7
0
 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[] { "" });
 }