コード例 #1
0
        internal static void PopulateCaptureDevices()
        {
            // clear microphones
            if (_allMicrophones != null)
            {
                _allMicrophones.Clear();
            }
            else
            {
                _allMicrophones = new List <Microphone>();
            }

            _default = null;

            // default device
            string defaultDevice = Alc.GetString(IntPtr.Zero, AlcGetString.CaptureDefaultDeviceSpecifier);

#if true //DESKTOPGL
            // enumerating capture devices
            IntPtr deviceList = Alc.alcGetString(IntPtr.Zero, (int)AlcGetString.CaptureDeviceSpecifier);

            // Marshal native UTF-8 character array to .NET string
            // The native string is a null-char separated list of known capture device specifiers ending with an empty string

            while (true)
            {
                var deviceIdentifier = InteropHelpers.Utf8ToString(deviceList);

                if (string.IsNullOrEmpty(deviceIdentifier))
                {
                    break;
                }

                var microphone = new Microphone(deviceIdentifier);
                _allMicrophones.Add(microphone);
                if (deviceIdentifier == defaultDevice)
                {
                    _default = microphone;
                }

                // increase the offset, add one extra for the terminator
                deviceList += deviceIdentifier.Length + 1;
            }
#else
            // Xamarin platforms don't provide an handle to alGetString that allow to marshal string arrays
            // so we're basically only adding the default microphone
            Microphone microphone = new Microphone(defaultDevice);
            _allMicrophones.Add(microphone);
            _default = microphone;
#endif
        }
コード例 #2
0
ファイル: Microphone.OpenAL.cs プロジェクト: jocamar/Caravel
        internal static void PopulateCaptureDevices()
        {
            // clear microphones
            if (_allMicrophones != null)
            {
                _allMicrophones.Clear();
            }
            else
            {
                _allMicrophones = new List <Microphone>();
            }

            _default = null;

            // default device
            string defaultDevice = Alc.GetString(IntPtr.Zero, AlcGetString.CaptureDefaultDeviceSpecifier);

#if true //DESKTOPGL
            // enumarating capture devices
            IntPtr deviceList = Alc.alcGetString(IntPtr.Zero, (int)AlcGetString.CaptureDeviceSpecifier);
            // we need to marshal a string array
            string deviceIdentifier = Marshal.PtrToStringAnsi(deviceList);
            while (!String.IsNullOrEmpty(deviceIdentifier))
            {
                Microphone microphone = new Microphone(deviceIdentifier);
                _allMicrophones.Add(microphone);
                if (deviceIdentifier == defaultDevice)
                {
                    _default = microphone;
                }
                deviceList      += deviceIdentifier.Length + 1;
                deviceIdentifier = Marshal.PtrToStringAnsi(deviceList);
            }
#else
            // Xamarin platforms don't provide an handle to alGetString that allow to marshal string arrays
            // so we're basically only adding the default microphone
            Microphone microphone = new Microphone(defaultDevice);
            _allMicrophones.Add(microphone);
            _default = microphone;
#endif
        }
コード例 #3
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);
        }