internal void Unregister(OpenALHardwareDeviceSession session)
 {
     lock (_lock)
     {
         _sessions.Remove(session);
     }
 }
        public IHardwareDeviceSession OpenDeviceSession(Direction direction, IVirtualMemoryManager memoryManager, SampleFormat sampleFormat, uint sampleRate, uint channelCount)
        {
            if (channelCount == 0)
            {
                channelCount = 2;
            }

            if (sampleRate == 0)
            {
                sampleRate = Constants.TargetSampleRate;
            }

            if (direction != Direction.Output)
            {
                throw new ArgumentException($"{direction}");
            }
            else if (!SupportsChannelCount(channelCount))
            {
                throw new ArgumentException($"{channelCount}");
            }

            lock (_lock)
            {
                OpenALHardwareDeviceSession session = new OpenALHardwareDeviceSession(this, memoryManager, sampleFormat, sampleRate, channelCount);

                _sessions.Add(session);

                return(session);
            }
        }
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                _stillRunning = false;

                int sessionCount = 0;

                // NOTE: This is done in a way to avoid possible situations when the OpenALHardwareDeviceSession is already being dispose in another thread but doesn't hold the lock and tries to Unregister.
                do
                {
                    lock (_lock)
                    {
                        if (_sessions.Count == 0)
                        {
                            break;
                        }

                        OpenALHardwareDeviceSession session = _sessions[_sessions.Count - 1];

                        session.Dispose();

                        sessionCount = _sessions.Count;
                    }
                }while (sessionCount > 0);

                ALC.DestroyContext(_context);
                ALC.CloseDevice(_device);
            }
        }
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                lock (_lock)
                {
                    _stillRunning = false;
                    _updaterThread.Join();

                    // Loop against all sessions to dispose them (they will unregister themself)
                    while (_sessions.Count > 0)
                    {
                        OpenALHardwareDeviceSession session = _sessions[0];

                        session.Dispose();
                    }
                }

                _context.Dispose();
            }
        }
Esempio n. 5
0
 internal bool Unregister(OpenALHardwareDeviceSession session)
 {
     return(_sessions.TryRemove(session, out _));
 }