Exemple #1
0
        protected override bool InitLibrary(IntPtr mainWindowHandle, int maxReal2DChannels, int maxReal3DChannels)
        {
            //NativeLibraryManager.PreLoadLibrary( "libogg" );
            //NativeLibraryManager.PreLoadLibrary( "libvorbis" );
            //NativeLibraryManager.PreLoadLibrary( "libvorbisfile" );

            //preload dlls
            {
                var fileNames = new List <string>();
                if (SystemSettings.CurrentPlatform == SystemSettings.Platform.Windows)
                {
                    fileNames.Add("OpenAL32.dll");
                }
                else if (SystemSettings.CurrentPlatform == SystemSettings.Platform.UWP)
                {
                    fileNames.Add("SDL2.dll");
                    fileNames.Add("OpenAL32.dll");
                }
                else if (SystemSettings.CurrentPlatform == SystemSettings.Platform.MacOS)
                {
                    fileNames.Add("OpenAL32.dylib");
                }
                else if (SystemSettings.CurrentPlatform == SystemSettings.Platform.Android)
                {
                    //fileNames.Add( "libOpenAL.so" );
                }
                else
                {
                    Log.Fatal("OpenALSoundWorld: InitLibrary: Unknown platform.");
                    return(false);
                }

                foreach (var fileName in fileNames)
                {
                    var path = Path.Combine(VirtualFileSystem.Directories.PlatformSpecific, fileName);
                    if (File.Exists(path))
                    {
                        NativeLibraryManager.PreLoadLibrary(fileName);
                    }
                }
            }

            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);
            }
            catch (Exception e)
            {
                Log.InvisibleInfo("OpenALSoundSystem: Open device failed. " + e.Message);
                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);
            }

            try
            {
                Alc.alcMakeContextCurrent(alContext);
            }
            catch (Exception e)
            {
                Log.InvisibleInfo("OpenALSoundSystem: alcMakeContextCurrent failed. " + e.Message);
                return(false);
            }

            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));
            try
            {
                if (SystemSettings.CurrentPlatform != SystemSettings.Platform.UWP)
                {
                    thread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
                }
            }
            catch { }
            thread.IsBackground = true;
            thread.Start();

            hWnd = mainWindowHandle;

            Al.alDistanceModel(Al.AL_NONE);

            return(true);
        }
Exemple #2
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;
		}