Exemplo n.º 1
0
 public AudioDevice(string device_name)
 {
     m_Handle   = IntPtr.Zero;
     m_Name     = device_name;
     m_Context  = null;
     m_Listener = null;
 }
Exemplo n.º 2
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);
        }