示例#1
0
        protected override bool InitLibrary(IntPtr mainWindowHandle,
                                            int maxReal2DChannels, int maxReal3DChannels)
        {
            instance = this;

            NativeLibraryManager.PreLoadLibrary("libogg");
            NativeLibraryManager.PreLoadLibrary("libvorbis");
            NativeLibraryManager.PreLoadLibrary("libvorbisfile");

            //preload OpenAL32
            {
                string fileName;
                if (PlatformInfo.Platform == PlatformInfo.Platforms.Windows)
                {
                    fileName = "OpenAL32.dll";
                }
                else if (PlatformInfo.Platform == PlatformInfo.Platforms.MacOSX)
                {
                    fileName = "OpenAL32.dylib";
                }
                else if (PlatformInfo.Platform == PlatformInfo.Platforms.Android)
                {
                    fileName = "libOpenAL32.so";
                }
                else
                {
                    Log.Fatal("OpenALSoundWorld: InitLibrary: Unknown platform.");
                    return(false);
                }

                string path = Path.Combine(NativeLibraryManager.GetNativeLibrariesDirectory(), fileName);
                if (File.Exists(path))
                {
                    NativeLibraryManager.PreLoadLibrary("OpenAL32");
                }
            }

            criticalSection = CriticalSection.Create();

            if (PlatformInfo.Platform == PlatformInfo.Platforms.Android)
            {
                Alc.alcSetJNIEnvironmentAndJavaVM(
                    EngineApp.Instance._CallCustomPlatformSpecificMethod("GetJNIEnvironment", IntPtr.Zero),
                    EngineApp.Instance._CallCustomPlatformSpecificMethod("GetJavaVM", IntPtr.Zero));
            }

            //string[] devices = Alc.alcGetStringv( IntPtr.Zero, Alc.ALC_DEVICE_SPECIFIER );

            try
            {
                alDevice = Alc.alcOpenDevice(null);
            }
            catch (DllNotFoundException)
            {
                Log.InvisibleInfo("OpenALSoundSystem: OpenAL not found.");
                return(false);
            }
            if (alDevice == IntPtr.Zero)
            {
                Log.InvisibleInfo("OpenALSoundSystem: No sound driver.");
                return(false);
            }

            alContext = Alc.alcCreateContext(alDevice, IntPtr.Zero);
            if (alContext == IntPtr.Zero)
            {
                Log.Error("OpenALSoundSystem: Create context failed.");
                return(false);
            }

            Alc.alcMakeContextCurrent(alContext);

            if (CheckError())
            {
                return(false);
            }

            //get captureDeviceName
            try
            {
                captureDeviceName = Alc.alcGetString(alDevice, Alc.ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
            }
            catch { }

            //Channels
            realChannels = new List <OpenALRealChannel>();
            for (int n = 0; n < maxReal2DChannels; n++)
            {
                OpenALRealChannel realChannel = new OpenALRealChannel();
                AddRealChannel(realChannel, false);
                realChannels.Add(realChannel);
            }
            for (int n = 0; n < maxReal3DChannels; n++)
            {
                OpenALRealChannel realChannel = new OpenALRealChannel();
                AddRealChannel(realChannel, true);
                realChannels.Add(realChannel);
            }

            fileStreamRealChannels = new List <OpenALRealChannel>();

            thread = new Thread(new ThreadStart(ThreadFunction));
            thread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
            thread.IsBackground   = true;
            thread.Start();

            hWnd = mainWindowHandle;

            Al.alDistanceModel(Al.AL_NONE);

            return(true);
        }