static void OnExit() { foreach (var stream in _inputStreams) { stream.Dispose(); } _context?.Dispose(); _context = null; }
// Scan and update the input device list. // It reuses object handles if their bound devices are still there. public void ScanAvailable(SoundIO.Context context) { var deviceCount = context.InputDeviceCount; var defaultIndex = context.DefaultInputDeviceIndex; var founds = new List <InputDeviceHandle>(); for (var i = 0; i < deviceCount; i++) { var dev = context.GetInputDevice(i); // Check if the device is useful. Reject it if not. if (dev.IsRaw || dev.Layouts.Length < 1) { dev.Dispose(); continue; } // Find the same device in the current list. var handle = _list.FindAndRemove(h => h.SioDevice.ID == dev.ID); if (handle != null) { // We reuse the handle, so this libsoundio device object // should be disposed. dev.Dispose(); } else { // Create a new handle with transferring the ownership of // this libsoundio device object. handle = InputDeviceHandle.CreateAndOwn(dev); } // Default device: Insert it at the head of the list. // Others: Simply append it to the list. if (i == defaultIndex) { founds.Insert(0, handle); } else { founds.Add(handle); } } // Dispose the remained handles (disconnected devices). foreach (var dev in _list) { dev.Dispose(); } // Replace the list with the new one. _list = founds; }
static SoundIO.Context GetContextWithLazyInitialization() { if (_context == null) { // libsoundio context initialization _context = SoundIO.Context.Create(); _context.OnDevicesChange = _onDevicesChangeDelegate; _context.Connect(); _context.FlushEvents(); // Install the Player Loop System. InsertPlayerLoopSystem(); } return(_context); }
static SoundIO.Context GetContextWithLazyInitialization() { if (_context == null) { // libsoundio context initialization _context = SoundIO.Context.Create(); _context.Connect(); _context.FlushEvents(); // Install the Player Loop System. InsertPlayerLoopSystem(); // Install the "on-exit" callback. UnityEngine.Application.quitting += OnExit; } return(_context); }