public VoipSession(UserDataManager userData)
        {
            _userData = userData;
            _nAudioTest = new AudioHardwareSession(Codec);
            _nAudioTest.InputDeviceNumber = App.Settings.AudioInputDeviceIndex;
            _nAudioTest.TriggerInput = _userData.Settings.MicTriggerInput;
            _nAudioTest.AudioRecorded += _nAudioTest_AudioRecorded;
            _nAudioTest.AudioRecordEnded += _nAudioTest_AudioRecordEnded;
            _nAudioTest.InputDeviceNumberChanged += _nAudioTest_InputDeviceNumberChanged;
            _nAudioTest.AudioSystemTick += _nAudioTest_AudioSystemTick;

            _udpKeepAliveTimer = new DispatcherTimer();
            _udpKeepAliveTimer.Interval = TimeSpan.FromSeconds(55);
            _udpKeepAliveTimer.Tick += _udpKeepAliveTimer_Tick;

            Connect();

            _micTrigger = SignalHelpers.ReadAudioResource("MicActivate.wav", Codec.RecordFormat);
        }
        public void Dispose()
        {
            _hasBeenDisposed = true;
            if (_nAudioTest == null)
                return;

            _nAudioTest.Dispose();
            _nAudioTest = null;

            lock (_audioChatSynch)
            {
                _audioChatClient.MessageReceived -= _audioChatClient_MessageReceived;
                _audioChatClient.Stopped -= _audioChatClient_Stopped;
                _audioChatClient.Stop();
                _audioChatClient = null;
            }

            _udpKeepAliveTimer.Stop();
        }
        private void _nAudioTest_AudioRecorded(AudioHardwareSession source, byte[] encoded, double signalPower)
        {
            var vt = _voiceTester;
            if (vt != null)
            {
                vt.Recorded(encoded, signalPower);
                return;
            }

            var isFirst = _speakingRoom == null;
            if (isFirst)
            {
                _speakingRoom = GetSpeakingRoom();
                _messageNumber = 0;
                _streamNumber++;

                _micTrigger.Index = 0;
            }

            if (_speakingRoom == null)
                return;

            if (isFirst)
            {
                if (UserDataManager.UserData.Settings.MicTriggerSoundOffEnabled)
                    Play(_micTrigger);

                _speakingRoomTeamOnly = _speakingRoom.R.IsVoiceTeamOnly;

                if (DebugSaveSentPackets)
                    _audioRec = new SerialPacketStream
                    {
                        Id = _userData.User.Id,
                        Parts = new List<SerialPacket>(),
                        IsEncoded = true,
                        RoomName = _speakingRoom.R.AudioRoomId,
                        StreamNumber = _streamNumber,
                    };
            }

            var message = new VoipMessageVoice
            {
                RoomName = _speakingRoom.R.AudioRoomId,
                FromUserId = _userData.User.Id,
                Audio = encoded,
                IsTeamOnly = _speakingRoomTeamOnly,
                MessageNumber = _messageNumber++,
                StreamNumber = _streamNumber,
            };

            if (DebugSaveSentPackets)
                _audioRec.Parts.Add(new SerialPacket(_audioRec.Parts.Count, encoded));

            _audioChatClient.Send(message);
            if (isFirst)
                _speakingRoom.OnVoiceSent(_userData.User);
        }
 internal void Init(AudioHardwareSession nAudioTest)
 {
     _nAudioTest = nAudioTest;
 }