Exemple #1
0
        private static void TryInitAudio()
        {
            int tries = 0;

            while (mAudioOn == false && tries < 10)
            {
                try
                {
                    mDeviceID = Alc.OpenDevice(null);
                    KWLogger.Log("Initializing OpenAL (Attempt #" + tries + ")", "GLAudioEngine::TryInitAudio");
                    Console.WriteLine("Initializing audio engine OpenAL (Attempt #" + tries + ")... ");
                    int[] attributes = new int[0];
                    mContext = Alc.CreateContext(mDeviceID, attributes);
                    Alc.MakeContextCurrent(mContext);
                    var version = AL.Get(ALGetString.Version);
                    var vendor  = AL.Get(ALGetString.Vendor);

                    if (version == null)
                    {
                        KWLogger.Log("No Audio devices found.", "GLAudioEngine::TryInitAudio", LogLevel.Error);
                        throw new Exception("No Audio devices found.");
                    }

                    Console.Write('\t' + version + " " + vendor);
                    Console.WriteLine(" Init complete.");
                    KWLogger.Log("Audio initialized: " + version + " " + vendor, "GLAudioEngine::TryInitAudio");
                    mAudioOn = true;
                }

                catch (Exception)
                {
                    mAudioOn = false;
                }

                if (mAudioOn == false)
                {
                    tries++;
                    Thread.Sleep(500);
                }
            }
            IsInitializing = false;

            if (mAudioOn)
            {
                for (int i = 0; i < mChannels; i++)
                {
                    GLAudioSource s = new GLAudioSource();
                    mSources.Add(s);
                }
            }
            else
            {
                Console.WriteLine("\t\t(Giving up on initializing the audio engine. Sorry.)");
                KWLogger.Log("Giving up on initializing the audio engine. Sorry.", "GLAudioEngine::TryInitAudio", LogLevel.Error);
            }
        }
Exemple #2
0
 internal static void ShowErrorAndQuit(string caption, string errormessage)
 {
     KWLogger.Log(errormessage, caption, LogLevel.Error);
     if (!KWEngine.GlobalError)
     {
         MessageBox.Show(errormessage, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
         KWEngine.GlobalError = true;
         KWEngine.CurrentWindow.ForceClose();
     }
 }
Exemple #3
0
 public static void InitAudioEngine()
 {
     KWLogger.Log("Initializing Audio...", "GLAudioEngine::InitAudioEngine");
     foreach (GLAudioSource s in mSources)
     {
         s.Clear();
     }
     mAudioInitThread = new Thread(new ThreadStart(TryInitAudio));
     mAudioInitThread.Start();
 }