Exemplo n.º 1
0
        protected bool init()
        {
            if (myIsInitialized == true)
            {
                return(true);
            }


            Info.print("------------------AUDIO MANAGER----------------");

            try
            {
                //try to get the DirectSound default (openAL-soft's target)
                string defaultDevice = AudioContext.DefaultDevice;
                myContext = new AudioContext(defaultDevice);
            }
            catch (AudioException ex)
            {
                Error.print("Exception trying to initialize OpenAL Context.  Verify OpenAL drivers are installed");
                Error.print("Exception: {0}", ex.Message);
                if (ex.InnerException != null)
                {
                    Error.print("Inner Exception: {0}", ex.InnerException.Message);
                }

                return(false);
            }

            //make the context current
            myContext.MakeCurrent();
            myContext.CheckErrors();
            myDevice = Alc.GetContextsDevice(Alc.GetCurrentContext());

            //print out the attributs
            int attributeSize = 0;

            Alc.GetInteger(myDevice, AlcGetInteger.AttributesSize, 1, out attributeSize);
            int[] attBuffer = new int[attributeSize * 2 + 1];
            Alc.GetInteger(myDevice, AlcGetInteger.AllAttributes, attributeSize * 2 + 1, attBuffer);
            int idx = 0;

            while (attBuffer[idx] != 0)
            {
                Info.print(String.Format("Context attribute: {0}:{1}", Audio.enumToString(attBuffer[idx]), attBuffer[idx + 1]));
                idx += 2;
            }

            //print some debug information about the system
            string alExtensions  = AL.Get(ALGetString.Extensions);
            string alcExtensions = Alc.GetString(myDevice, AlcGetString.Extensions);

            Info.print("Opened Audio device {0}", myContext.ToString());
            Info.print("OpenAL Vendor: {0}", AL.Get(ALGetString.Vendor));
            Info.print("OpenAL Version: {0}", AL.Get(ALGetString.Version));
            Info.print("OpenAL Renderer: {0}", AL.Get(ALGetString.Renderer));
            Info.print("OpenAL Extensions: {0}", AL.Get(ALGetString.Extensions));
            Info.print("OpenAL Context Extensions: {0} ", Alc.GetString(myDevice, AlcGetString.Extensions));



            string[] extensions = alcExtensions.Split(' ');
            for (int i = 0; i < extensions.Length; i++)
            {
                if (extensions[i] == "ALC_EXT_EFX")
                {
                    myEnvironmentalProcessingAvailable = true;
                }
            }

            Info.print("Environmental Processing: " + (myEnvironmentalProcessingAvailable ? "available" : "unavailable"));

            createVoices(myMaxVoices);

            Info.print("------------------AUDIO MANAGER----------------");

            return(true);
        }