Esempio n. 1
0
        private void DrawQualitySettings([NotNull] VoiceSettings settings)
        {
            using (new EditorGUI.DisabledGroupScope(Application.isPlaying))
            {
                EditorGUILayout.Space();

                var f = (FrameSize)EditorGUILayout.EnumPopup("Frame Size", settings.FrameSize);
                if (!Application.isPlaying)
                {
                    settings.FrameSize = f;
                }
                EditorGUILayout.HelpBox(
                    "A smaller frame size will send smaller packets of data more frequently, improving latency at the expense of some network and CPU performance.\n\n" +
                    "A larger frame size will send larger packets of data less frequently, gaining some network and CPU performance at the expense of latency.",
                    MessageType.Info);

                var q = (AudioQuality)EditorGUILayout.EnumPopup("Audio Quality", settings.Quality);
                if (!Application.isPlaying)
                {
                    settings.Quality = q;
                }
                EditorGUILayout.HelpBox(
                    "A lower quality setting uses less CPU and bandwidth, but sounds worse.\n\n" +
                    "A higher quality setting uses more CPU and bandwidth, but sounds better.",
                    MessageType.Info);

                if (Application.isPlaying)
                {
                    EditorGUILayout.HelpBox(
                        "Quality settings cannot be changed at runtime",
                        MessageType.Warning);
                }
            }
        }
Esempio n. 2
0
        private void DrawPreprocessorSettings(VoiceSettings settings)
        {
            settings.DenoiseAmount = (NoiseSuppressionLevels)EditorGUILayout.EnumPopup(new GUIContent("Noise Suppression"), settings.DenoiseAmount);
            EditorGUILayout.HelpBox("A higher value will remove more background noise but risks attenuating speech.\n\n" +
                                    "A lower value will remove less noise, but will attenuate speech less.", MessageType.Info);

            //settings.Denoise = EditorGUILayout.Toggle("De-Noise", settings.Denoise);
            //EditorGUI.indentLevel++;
            //using (new EditorGUI.DisabledGroupScope(!settings.Denoise))
            //{
            //    settings.DenoiseMaxAttenuation = -(int)EditorGUILayout.Slider("Max Attenuation (dB)", -settings.DenoiseMaxAttenuation, 0, 100);
            //}
            //EditorGUI.indentLevel--;

            //EditorGUILayout.Space();

            //settings.AGC = EditorGUILayout.Toggle("Automatic Gain Control", settings.AGC);
            //EditorGUI.indentLevel++;
            //using (new EditorGUI.DisabledGroupScope(!settings.AGC))
            //{
            //    settings.AgcTargetLevel = EditorGUILayout.Slider("Target", settings.AgcTargetLevel / 32768 * 100, 1, 100) * 32768 / 100;
            //    settings.AgcMaxGain = (int)EditorGUILayout.Slider("Max Gain (dB)", settings.AgcMaxGain, 1, 100);
            //    settings.AgcGainIncrement = (int)EditorGUILayout.Slider("Gain Increment (dB/s)", settings.AgcGainIncrement, 1, 100);
            //    settings.AgcGainDecrement = -(int)EditorGUILayout.Slider("Gain Decrement (dB/s)", -settings.AgcGainDecrement, 1, 100);
            //}
            //EditorGUI.indentLevel--;
        }
        private void OnEnable()
        {
            VoiceSettings.Preload();
            DebugSettings.Preload();

            ClipsDropdown.options.Clear();
            for (var i = 0; i < Clips.Length; i++)
            {
                ClipsDropdown.options.Add(new Dropdown.OptionData(Clips[i].name));
            }

            NoiseSuppressionDropdown.options.Clear();
            foreach (var item in Enum.GetNames(typeof(NoiseSuppressionLevels)))
            {
                NoiseSuppressionDropdown.options.Add(new Dropdown.OptionData(item));
            }
            NoiseSuppressionDropdown.value = (int)VoiceSettings.Instance.DenoiseAmount;

            VadSensitivityDropdown.options.Clear();
            foreach (var item in Enum.GetNames(typeof(VadSensitivityLevels)))
            {
                VadSensitivityDropdown.options.Add(new Dropdown.OptionData(item));
            }
            NoiseSuppressionDropdown.value = (int)VoiceSettings.Instance.VadSensitivity;

            BackgroundSoundRemoval.isOn        = VoiceSettings.Instance.BackgroundSoundRemovalEnabled;
            BackgroundSoundRemovalSlider.value = VoiceSettings.Instance.BackgroundSoundRemovalAmount;

            _enabled = true;

            OnAudioSelectionChanged();
            OnPlayPauseClicked();
        }
Esempio n. 4
0
        private void DrawQualitySettings([NotNull] VoiceSettings settings)
        {
            using (new EditorGUI.DisabledGroupScope(Application.isPlaying))
            {
                EditorGUILayout.Space();

                using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
                {
                    var f = (FrameSize)EditorGUILayout.EnumPopup("Frame Size", settings.FrameSize);
                    if (!Application.isPlaying)
                    {
                        settings.FrameSize = f;
                    }

                    if (f == FrameSize.Tiny)
                    {
                        EditorGUILayout.HelpBox(string.Format("'{0}' frame size is only suitable for LAN usage due to very high bandwidth overhead!", FrameSize.Tiny), MessageType.Warning);
                    }

                    EditorGUILayout.HelpBox(
                        "• A smaller frame size will send smaller packets of data more frequently, improving latency at the expense of some network and CPU performance.\n" +
                        "• A larger frame size will send larger packets of data less frequently, gaining some network and CPU performance at the expense of latency.",
                        MessageType.Info
                        );
                }

                using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
                {
                    var q = (AudioQuality)EditorGUILayout.EnumPopup("Audio Quality", settings.Quality);
                    if (!Application.isPlaying)
                    {
                        settings.Quality = q;
                    }
                    EditorGUILayout.HelpBox(
                        "• A lower quality setting uses less CPU and bandwidth, but sounds worse.\n" +
                        "• A higher quality setting uses more CPU and bandwidth, but sounds better.",
                        MessageType.Info);
                }

                using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
                {
                    var fec = EditorGUILayout.Toggle("Forward Error Correction", settings.ForwardErrorCorrection);
                    if (!Application.isPlaying)
                    {
                        settings.ForwardErrorCorrection = fec;
                    }
                    EditorGUILayout.HelpBox(
                        "When network conditions are bad (high packet loss) use slightly more bandwidth to significantly improve audio quality.",
                        MessageType.Info);
                }

                if (Application.isPlaying)
                {
                    EditorGUILayout.HelpBox(
                        "Quality settings cannot be changed at runtime",
                        MessageType.Warning);
                }
            }
        }
Esempio n. 5
0
 private void DrawOtherSettings([NotNull] VoiceSettings settings)
 {
     using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
     {
         settings.VoiceDuckLevel = EditorGUILayout.Slider("Audio Duck Attenuation", settings.VoiceDuckLevel, 0f, 1f);
         EditorGUILayout.HelpBox("How much remote voice volume will be reduced when local speech is being transmitted.\n\n" +
                                 "A lower value will attenuate more but risks making remote speakers inaudible.", MessageType.Info);
     }
 }
Esempio n. 6
0
 private void DrawOtherSettings([NotNull] VoiceSettings settings)
 {
     using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
     {
         settings.VoiceDuckLevel = Helpers.FromDecibels(EditorGUILayout.Slider("Audio Duck Attenuation (dB)", Helpers.ToDecibels(settings.VoiceDuckLevel), Helpers.MinDecibels, 0));
         EditorGUILayout.HelpBox("• How much remote voice volume will be reduced when local speech is being transmitted.\n" +
                                 "• A lower value will attenuate more but risks making remote speakers inaudible.", MessageType.Info);
     }
 }
Esempio n. 7
0
        private void DrawPreprocessorSettings([NotNull] VoiceSettings settings)
        {
            using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
            {
                settings.DenoiseAmount = (NoiseSuppressionLevels)EditorGUILayout.EnumPopup(new GUIContent("Noise Suppression"), settings.DenoiseAmount);
                EditorGUILayout.HelpBox("A higher value will remove more background noise but risks attenuating speech.\n\n" +
                                        "A lower value will remove less noise, but will attenuate speech less.",
                                        MessageType.Info);
            }

            using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
            {
                EditorGUILayout.HelpBox("Acoustic Echo Cancellation is experimental!", MessageType.Warning);

                settings.AecmRoutingMode      = (AecmRoutingMode)EditorGUILayout.EnumPopup(new GUIContent("Mobile Echo Cancellation"), settings.AecmRoutingMode);
                settings.AecSuppressionAmount = (AecSuppressionLevels)EditorGUILayout.EnumPopup(new GUIContent("Desktop Echo Cancellation"), settings.AecSuppressionAmount);
                EditorGUILayout.HelpBox("A higher value will remove more echo, but risks distorting speech.\n\n" +
                                        "A lower value will remove less echo, but will distort speech less.",
                                        MessageType.Info);

                EditorGUI.indentLevel++;
                _showAecAdvanced = EditorGUILayout.Foldout(_showAecAdvanced, new GUIContent("Advanced Desktop Options"), true);
                EditorGUI.indentLevel--;
                if (_showAecAdvanced)
                {
                    using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
                        using (new EditorGUI.DisabledGroupScope(Application.isPlaying))
                        {
                            if (Application.isPlaying)
                            {
                                EditorGUILayout.HelpBox("AEC advanced configuration cannot be changed at runtime", MessageType.Warning);
                            }

                            settings.AecDelayAgnostic         = EditorGUILayout.Toggle(new GUIContent("Delay Agnostic Mode"), settings.AecDelayAgnostic);
                            settings.AecExtendedFilter        = EditorGUILayout.Toggle(new GUIContent("Extended Filter"), settings.AecExtendedFilter);
                            settings.AecRefinedAdaptiveFilter = EditorGUILayout.Toggle(new GUIContent("Refined Adaptive Filter"), settings.AecRefinedAdaptiveFilter);
                        }
                }

                EditorGUI.indentLevel++;
                _showAecmAdvanced = EditorGUILayout.Foldout(_showAecmAdvanced, new GUIContent("Advanced Mobile Options"), true);
                EditorGUI.indentLevel--;
                if (_showAecmAdvanced)
                {
                    using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
                        using (new EditorGUI.DisabledGroupScope(Application.isPlaying))
                        {
                            if (Application.isPlaying)
                            {
                                EditorGUILayout.HelpBox("AECM advanced configuration cannot be changed at runtime", MessageType.Warning);
                            }

                            settings.AecmComfortNoise = EditorGUILayout.Toggle(new GUIContent("Comfort Noise"), settings.AecmComfortNoise);
                        }
                }
            }
        }
Esempio n. 8
0
        public void Initialize(AppSettings appSettings)
        {
            string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

            this.Window = new WindowSettings();
            this.View   = new ViewSettings();
            this.CommonDirectoryPath = folderPath;
            this.TextDirectoryPath   = folderPath;
            this.KanaDirectoryPath   = folderPath;
            this.WaveDirectoryPath   = folderPath;
            this.TextFormat          = new TextFormatSettings();
            this.Find = new FindSettings();
            this.VoiceSamplePerSec = AppModeUtil.CheckSupport(appSettings.AppMode, AppMode.MicroVoice) ? 0x3e80 : 0x5622;
            if (appSettings.Function.UseConstVoiceDic)
            {
                this._constDbsPath = appSettings.Function.ConstVoiceDicPath;
            }
            else
            {
                this._constDbsPath = "";
                this.DbsPath       = Path.Combine(Directory.GetParent(Application.StartupPath).FullName, "voice");
            }
            if (appSettings.Function.UseConstLangDic)
            {
                this._constLangPath = appSettings.Function.ConstLangDicPath;
            }
            else
            {
                this._constLangPath = "";
                this.LangPath       = Path.Combine(Application.StartupPath, AppModeUtil.CheckSupport(appSettings.AppMode, AppMode.MicroLang) ? @"lang\normal" : "lang");
            }
            this.SoundOutput                = new SoundOutputSettings(this.VoiceSamplePerSec);
            this.KanaMode                   = KanaFormat.AIKANA;
            this.IgnoredVoiceNames          = new List <string>();
            this.SelectedVoiceName          = "";
            this.UserDic                    = new UserDicSettings(appSettings);
            this.MasterVolume               = 1f;
            this.BeginPause                 = 0;
            this.TermPause                  = 0;
            this.HandleNewLineAsSentenceEnd = true;
            this.UseCommonVoiceSettings     = true;
            this.CommonVoice                = new VoiceSettings();
            this.Voice = new List <VoiceSettings>();
            this.Jeita = new JeitaSettings();
        }
Esempio n. 9
0
        private void Start()
        {
            //Ensure that all settings are loaded before we access them (potentially from other threads)
            ChatRoomSettings.Preload();
            DebugSettings.Preload();
            VoiceSettings.Preload();

            //Write multithreaded logs ASAP so the logging system knows which is the main thread
            Logs.WriteMultithreadedLogs();

            //Sanity check (can't run without a network object)
            var net = gameObject.GetComponent <ICommsNetwork>();

            if (net == null)
            {
                throw new Exception("Cannot find a voice network component. Please attach a voice network component appropriate to your network system to the DissonanceVoiceComms' entity.");
            }

            //Sanity check (can't run without run in background). This value doesn't work on mobile platforms so don't perform this check there
            if (!Application.isMobilePlatform && !Application.runInBackground)
            {
                Log.Error(Log.UserErrorMessage(
                              "Run In Background is not set",
                              "The 'Run In Background' toggle on the player settings has not been checked",
                              "https://dissonance.readthedocs.io/en/latest/Basics/Getting-Started/#3-run-in-background",
                              "98D123BB-CF4F-4B41-8555-41CD01108DA7")
                          );
            }

            //Load default playback prefab if one has not been set
            if (PlaybackPrefab == null)
            {
                Log.Info("Loading default playback prefab");
                PlaybackPrefab = Resources.Load <GameObject>("PlaybackPrefab").GetComponent <VoicePlayback>();
            }

            net.PlayerJoined          += Net_PlayerJoined;
            net.PlayerLeft            += Net_PlayerLeft;
            net.PlayerEnteredRoom     += Net_PlayerRoomEvent;
            net.PlayerExitedRoom      += Net_PlayerRoomEvent;
            net.VoicePacketReceived   += Net_VoicePacketReceived;
            net.PlayerStartedSpeaking += Net_PlayerStartedSpeaking;
            net.PlayerStoppedSpeaking += Net_PlayerStoppedSpeaking;
            net.TextPacketReceived    += _text.OnMessageReceived;

            //If an explicit name has not been set generate a GUID based name
            if (string.IsNullOrEmpty(LocalPlayerName))
            {
                var guid = Guid.NewGuid().ToString();
                LocalPlayerName = guid;
            }

            //mark this component as started, locking the LocalPlayerName, PlaybackPrefab and Microphone properties from changing
            _started = true;

            //Setup the playback pool so we can create pipelines to play audio
            _playbackPool.Start(PlaybackPrefab, transform);

            //Make sure we load up the codec settings so we can create codecs later
            _codecSettings.Start();

            //Start the player collection (to set local name)
            _players.Start(LocalPlayerName, _capture, Rooms, RoomChannels, PlayerChannels);

            net.Initialize(LocalPlayerName, Rooms, PlayerChannels, RoomChannels);
            _net = net;

            //Begin capture manager, this will create and destroy capture pipelines as necessary (net mode changes, mic name changes, mic requires reset etc)
            _capture.MicrophoneName = _micName;
            _capture.Start(_net, GetOrAddMicrophone());
        }
Esempio n. 10
0
 public OpusCodec()
 {
     _settings = Singleton.Of <Configuration>().VoiceSettings;
 }
Esempio n. 11
0
        [UsedImplicitly] private void Start()
        {
            // Unity is unreliable about late loading DLLs so try to load dependencies as early as possible.
            try
            {
                TestDependencies();
            }
            catch (Exception e)
            {
                Log.Error("Dependency Error: {0}", e.Message);
            }

            //Ensure that all settings are loaded before we access them (potentially from other threads)
            ChatRoomSettings.Preload();
            DebugSettings.Preload();
            VoiceSettings.Preload();

            //Write multithreaded logs ASAP so the logging system knows which is the main thread
            Logs.WriteMultithreadedLogs();

            //Sanity check (can't run without a network object)
            var net = gameObject.GetComponent <ICommsNetwork>();

            if (net == null)
            {
                throw new Exception("Cannot find a voice network component. Please attach a voice network component appropriate to your network system to the DissonanceVoiceComms' entity.");
            }

            //Sanity check (can't run without run in background). This value doesn't work on mobile platforms so don't perform this check there
            if (!Application.isMobilePlatform && !Application.runInBackground)
            {
                Log.Error(Log.UserErrorMessage(
                              "Run In Background is not set",
                              "The 'Run In Background' toggle on the player settings has not been checked",
                              "https://dissonance.readthedocs.io/en/latest/Basics/Getting-Started/#3-run-in-background",
                              "98D123BB-CF4F-4B41-8555-41CD01108DA7")
                          );
            }

            //Load default playback prefab if one has not been set
            if (PlaybackPrefab == null)
            {
                //Check if there is a legacy playback prefab set
                if (_playbackPrefab != null)
                {
                    PlaybackPrefab = _playbackPrefab.gameObject;
                }
                else
                {
                    Log.Info("Loading default playback prefab");
                    PlaybackPrefab = Resources.Load <GameObject>("PlaybackPrefab");

                    if (PlaybackPrefab == null)
                    {
                        throw Log.CreateUserErrorException("Failed to load PlaybackPrefab from resources - Dissonance voice will be disabled", "Incorrect installation of Dissonance", "https://dissonance.readthedocs.io/en/latest/Basics/Getting-Started/", "F542DAE5-AB78-4ADE-8FF0-4573233505AB");
                    }
                }
            }

            net.PlayerJoined          += Net_PlayerJoined;
            net.PlayerLeft            += Net_PlayerLeft;
            net.PlayerEnteredRoom     += Net_PlayerRoomEvent;
            net.PlayerExitedRoom      += Net_PlayerRoomEvent;
            net.VoicePacketReceived   += Net_VoicePacketReceived;
            net.PlayerStartedSpeaking += Net_PlayerStartedSpeaking;
            net.PlayerStoppedSpeaking += Net_PlayerStoppedSpeaking;
            net.TextPacketReceived    += _text.OnMessageReceived;

            //If an explicit name has not been set generate a GUID based name
            if (string.IsNullOrEmpty(LocalPlayerName))
            {
                var guid = Guid.NewGuid().ToString();
                LocalPlayerName = guid;
            }

            //mark this component as started, locking the LocalPlayerName, PlaybackPrefab and Microphone properties from changing
            _started = true;

            //Setup the playback pool so we can create pipelines to play audio
            _playbackPool.Start(PlaybackPrefab, transform);

            //Make sure we load up the codec settings so we can create codecs later
            _codecSettingsLoader.Start();

            //Start the player collection (to set local name)
            _players.Start(LocalPlayerName, _capture, Rooms, RoomChannels, PlayerChannels, _capture, net);

            net.Initialize(LocalPlayerName, Rooms, PlayerChannels, RoomChannels, _codecSettingsLoader.Config);
            _net = net;

            //Begin capture manager, this will create and destroy capture pipelines as necessary (net mode changes, mic name changes, mic requires reset etc)
            _capture.MicrophoneName = _micName;
            _capture.Start(_net, GetOrAddMicrophone());

            Log.Info("Starting Dissonance Voice Comms ({0})\n- Network: [{1}]\n- Quality Settings: [{2}]\n- Codec: [{3}]", Version, _net, VoiceSettings.Instance, _codecSettingsLoader);
        }
Esempio n. 12
0
 private void DrawPreprocessorSettings([NotNull] VoiceSettings settings)
 {
     settings.DenoiseAmount = (NoiseSuppressionLevels)EditorGUILayout.EnumPopup(new GUIContent("Noise Suppression"), settings.DenoiseAmount);
     EditorGUILayout.HelpBox("A higher value will remove more background noise but risks attenuating speech.\n\n" +
                             "A lower value will remove less noise, but will attenuate speech less.", MessageType.Info);
 }
Esempio n. 13
0
        private void DrawPreprocessorSettings([NotNull] VoiceSettings settings)
        {
            using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
            {
                settings.DenoiseAmount = (NoiseSuppressionLevels)EditorGUILayout.EnumPopup(new GUIContent("Noise Suppression"), settings.DenoiseAmount);
                EditorGUILayout.HelpBox("• A higher value will remove more background noise (e.g. fans) but risks attenuating speech.\n" +
                                        "• A lower value will remove less noise, but will attenuate speech less.",
                                        MessageType.Info);
            }

            using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
            {
                EditorGUILayout.HelpBox("Background Sound Removal is currently experimental!", MessageType.Warning);

                settings.BackgroundSoundRemovalEnabled = EditorGUILayout.Toggle(new GUIContent("Background Sound Removal"), settings.BackgroundSoundRemovalEnabled);
                EditorGUILayout.HelpBox("• Enable machine learning based background sound removal (Rnnoise).\n" +
                                        "• Removes more non-speech background sounds (e.g. keyboard sounds) than classic noise suppression but risks distorting speech.", MessageType.Info);

                using (new EditorGUI.DisabledGroupScope(!settings.BackgroundSoundRemovalEnabled))
                {
                    settings.BackgroundSoundRemovalAmount = EditorGUILayout.Slider("Background Sound Removal Intensity", settings.BackgroundSoundRemovalAmount, 0, 1);

                    EditorGUILayout.HelpBox("• A higher value will remove more background sound but risks distorting speech.\n" +
                                            "• A lower value will remove less background sound but will distort speech less.",
                                            MessageType.Info);
                }
            }

            using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
            {
                settings.VadSensitivity = (VadSensitivityLevels)EditorGUILayout.EnumPopup(new GUIContent("Voice Detector Sensitivity"), settings.VadSensitivity);
                EditorGUILayout.HelpBox("• A higher value will detect more voice, but may also allow through more non-voice.\n" +
                                        "• A lower value will allow through less non-voice, but may not detect some speech.",
                                        MessageType.Info);
            }

            using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
            {
                EditorGUILayout.HelpBox("Ensure that you have followed the AEC setup instructions before enabling AEC:\n" +
                                        "https://placeholder-software.co.uk/dissonance/docs/Tutorials/Acoustic-Echo-Cancellation", MessageType.Warning);

                settings.AecmRoutingMode      = (AecmRoutingMode)EditorGUILayout.EnumPopup(new GUIContent("Mobile Echo Cancellation"), settings.AecmRoutingMode);
                settings.AecSuppressionAmount = (AecSuppressionLevels)EditorGUILayout.EnumPopup(new GUIContent("Desktop Echo Cancellation"), settings.AecSuppressionAmount);
                EditorGUILayout.HelpBox("• A higher value will remove more echo, but risks distorting speech.\n" +
                                        "• A lower value will remove less echo, but will distort speech less.",
                                        MessageType.Info);

                EditorGUI.indentLevel++;
                _showAecAdvanced = EditorGUILayout.Foldout(_showAecAdvanced, new GUIContent("Advanced Desktop Options"), true);
                EditorGUI.indentLevel--;
                if (_showAecAdvanced)
                {
                    using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
                        using (new EditorGUI.DisabledGroupScope(Application.isPlaying))
                        {
                            if (Application.isPlaying)
                            {
                                EditorGUILayout.HelpBox("AEC advanced configuration cannot be changed at runtime", MessageType.Warning);
                            }

                            settings.AecDelayAgnostic         = EditorGUILayout.Toggle(new GUIContent("Delay Agnostic Mode"), settings.AecDelayAgnostic);
                            settings.AecExtendedFilter        = EditorGUILayout.Toggle(new GUIContent("Extended Filter"), settings.AecExtendedFilter);
                            settings.AecRefinedAdaptiveFilter = EditorGUILayout.Toggle(new GUIContent("Refined Adaptive Filter"), settings.AecRefinedAdaptiveFilter);
                        }
                }

                EditorGUI.indentLevel++;
                _showAecmAdvanced = EditorGUILayout.Foldout(_showAecmAdvanced, new GUIContent("Advanced Mobile Options"), true);
                EditorGUI.indentLevel--;
                if (_showAecmAdvanced)
                {
                    using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
                        using (new EditorGUI.DisabledGroupScope(Application.isPlaying))
                        {
                            if (Application.isPlaying)
                            {
                                EditorGUILayout.HelpBox("AECM advanced configuration cannot be changed at runtime", MessageType.Warning);
                            }

                            settings.AecmComfortNoise = EditorGUILayout.Toggle(new GUIContent("Comfort Noise"), settings.AecmComfortNoise);
                        }
                }
            }
        }
Esempio n. 14
0
        private void Start()
        {
            //Ensure that all settings are loaded before we access them (potentially from other threads)
            DebugSettings.Preload();
            VoiceSettings.Preload();

            //Write multithreaded logs ASAP so the logging system knows which is the main thread
            Logs.WriteMultithreadedLogs();

            var net = gameObject.GetComponent <ICommsNetwork>();

            if (net == null)
            {
                throw new Exception("Cannot find a voice network component. Please attach a voice network component appropriate to your network system to the DissonanceVoiceComms' entity.");
            }

            if (PlaybackPrefab == null)
            {
                Log.Info("Loading default playback prefab");
                PlaybackPrefab = Resources.Load <GameObject>("PlaybackPrefab").GetComponent <VoicePlayback>();
            }

            net.PlayerJoined          += Net_PlayerJoined;
            net.PlayerLeft            += Net_PlayerLeft;
            net.VoicePacketReceived   += Net_VoicePacketReceived;
            net.PlayerStartedSpeaking += Net_PlayerStartedSpeaking;
            net.PlayerStoppedSpeaking += Net_PlayerStoppedSpeaking;
            net.TextPacketReceived    += _text.OnMessageReceived;

            if (string.IsNullOrEmpty(LocalPlayerName))
            {
                var guid = Guid.NewGuid().ToString();
                LocalPlayerName = guid;
            }

            //mark this component as started, locking the LocalPlayerName, PlaybackPrefab and Microphone properties from changing
            _started = true;

            MicCapture = MicrophoneCapture.Start(_micName);

            _localPlayerState = new LocalVoicePlayerState(LocalPlayerName, this);
            _players.Add(_localPlayerState);
            _playersLookup.Add(LocalPlayerName, _localPlayerState);

            Action <NetworkMode> networkModeChanged = mode =>
            {
                if (mode.IsClientEnabled())
                {
                    var encoder = new OpusEncoder(VoiceSettings.Instance.Quality, VoiceSettings.Instance.FrameSize);
                    _decoderFrameSize  = (uint)encoder.FrameSize;
                    _decoderSampleRate = encoder.SampleRate;

                    _transmissionPipeline = new EncoderPipeline(MicCapture, encoder, _net, () => _playerChannels.Count + _roomChannels.Count);

                    for (var i = 0; i < _activationListeners.Count; i++)
                    {
                        MicCapture.Subscribe(_activationListeners[i]);
                    }
                }
                else
                {
                    if (_transmissionPipeline != null)
                    {
                        _transmissionPipeline.Dispose();
                        _transmissionPipeline = null;
                    }

                    for (var i = 0; i < _activationListeners.Count; i++)
                    {
                        MicCapture.Unsubscribe(_activationListeners[i]);
                    }
                }
            };

            if (MicCapture != null)
            {
                net.ModeChanged += networkModeChanged;
            }
            else
            {
                Log.Warn("No microphone detected; local voice transmission will be disabled.");
            }

            net.Initialize(LocalPlayerName, Rooms, PlayerChannels, RoomChannels);
            _net = net;
        }
Esempio n. 15
0
        public bool Validate(AppSettings appSettings)
        {
            bool   flag       = false;
            string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

            if (this.Window == null)
            {
                this.Window = new WindowSettings();
                flag        = true;
            }
            if (this.View == null)
            {
                this.View = new ViewSettings();
                flag      = true;
            }
            if (this.CommonDirectoryPath == null)
            {
                this.CommonDirectoryPath = folderPath;
            }
            if (this.TextDirectoryPath == null)
            {
                this.TextDirectoryPath = folderPath;
            }
            if (this.KanaDirectoryPath == null)
            {
                this.KanaDirectoryPath = folderPath;
            }
            if (this.WaveDirectoryPath == null)
            {
                this.WaveDirectoryPath = folderPath;
            }
            if (this.TextFormat == null)
            {
                this.TextFormat = new TextFormatSettings();
                flag            = true;
            }
            else
            {
                try
                {
                    new Font(this.TextFormat.FontFamilyName, this.TextFormat.Size, this.TextFormat.Style, this.TextFormat.Unit, this.TextFormat.GdiCharSet, this.TextFormat.GdiVerticalFont);
                }
                catch
                {
                    this.TextFormat = new TextFormatSettings();
                    flag            = true;
                }
            }
            if (this.Find == null)
            {
                this.Find = new FindSettings();
                flag      = true;
            }
            else
            {
                if ((this.Find.Target != FindSettings.TargetField.Text) && (this.Find.Target != FindSettings.TargetField.Yomi))
                {
                    this.Find.Target = FindSettings.TargetField.Text;
                    flag             = true;
                }
                if ((this.Find.Logic != FindSettings.LogicalCondition.And) && (this.Find.Logic != FindSettings.LogicalCondition.Or))
                {
                    this.Find.Logic = FindSettings.LogicalCondition.And;
                    flag            = true;
                }
                if (((this.Find.Match != FindSettings.MatchingCondition.Forward) && (this.Find.Match != FindSettings.MatchingCondition.Backward)) && (this.Find.Match != FindSettings.MatchingCondition.Partial))
                {
                    this.Find.Match = FindSettings.MatchingCondition.Partial;
                    flag            = true;
                }
                if ((this.Find.PageSize < 1) || (this.Find.PageSize > 0xea60))
                {
                    this.Find.PageSize = 100;
                    flag = true;
                }
            }
            if ((this.VoiceSamplePerSec != 0x5622) && (this.VoiceSamplePerSec != 0x3e80))
            {
                this.VoiceSamplePerSec = AppModeUtil.CheckSupport(appSettings.AppMode, AppMode.MicroVoice) ? 0x3e80 : 0x5622;
                flag = true;
            }
            if (appSettings.Function.UseConstVoiceDic)
            {
                this._constDbsPath = appSettings.Function.ConstVoiceDicPath;
            }
            else
            {
                this._constDbsPath = "";
                if (this.DbsPath == null)
                {
                    this.DbsPath = Path.Combine(Directory.GetParent(Application.StartupPath).FullName, "voice");
                    flag         = true;
                }
            }
            if (appSettings.Function.UseConstLangDic)
            {
                this._constLangPath = appSettings.Function.ConstLangDicPath;
            }
            else
            {
                this._constLangPath = "";
                if (this.LangPath == null)
                {
                    this.LangPath = Path.Combine(Application.StartupPath, AppModeUtil.CheckSupport(appSettings.AppMode, AppMode.MicroLang) ? @"lang\normal" : "lang");
                    flag          = true;
                }
            }
            if (this.SoundOutput == null)
            {
                this.SoundOutput = new SoundOutputSettings(this.VoiceSamplePerSec);
                flag             = true;
            }
            else
            {
                if ((this.SoundOutput.SamplePerSec != this.VoiceSamplePerSec) && (this.SoundOutput.SamplePerSec != (this.VoiceSamplePerSec / 2)))
                {
                    this.SoundOutput.SamplePerSec = this.VoiceSamplePerSec;
                    flag = true;
                }
                if (((this.SoundOutput.DataFormat != AIAudioFormatType.AIAUDIOTYPE_PCM_16) && (this.SoundOutput.DataFormat != AIAudioFormatType.AIAUDIOTYPE_MULAW_8)) || ((this.SoundOutput.DataFormat == AIAudioFormatType.AIAUDIOTYPE_MULAW_8) && (this.SoundOutput.SamplePerSec != 0x1f40)))
                {
                    this.SoundOutput.DataFormat = AIAudioFormatType.AIAUDIOTYPE_PCM_16;
                    flag = true;
                }
            }
            if ((this.KanaMode != KanaFormat.AIKANA) && (this.KanaMode != KanaFormat.JEITA))
            {
                this.KanaMode = KanaFormat.AIKANA;
                flag          = true;
            }
            if (this.IgnoredVoiceNames == null)
            {
                this.IgnoredVoiceNames = new List <string>();
                flag = true;
            }
            if (this.SelectedVoiceName == null)
            {
                this.SelectedVoiceName = "";
                flag = true;
            }
            if (this.UserDic == null)
            {
                this.UserDic = new UserDicSettings(appSettings);
                flag         = true;
            }
            else
            {
                if (this.UserDic.WordDicPath == null)
                {
                    this.UserDic.WordDicPath = appSettings.UserDic.DefaultWordDicFilePath;
                    flag = true;
                }
                if (this.UserDic.PhraseDicPath == null)
                {
                    this.UserDic.PhraseDicPath = appSettings.UserDic.DefaultPhraseDicFilePath;
                    flag = true;
                }
                if (this.UserDic.SymbolDicPath == null)
                {
                    this.UserDic.SymbolDicPath = appSettings.UserDic.DefaultSymbolDicFilePath;
                    flag = true;
                }
            }
            if ((this.MasterVolume < 0.01) || (this.MasterVolume > 5.0))
            {
                this.MasterVolume = 1f;
                flag = true;
            }
            if ((this.BeginPause < 0) || (this.BeginPause > 0x2710))
            {
                this.BeginPause = 0;
                flag            = true;
            }
            if ((this.TermPause < 0) || (this.TermPause > 0x2710))
            {
                this.TermPause = 0;
                flag           = true;
            }
            this.UseCommonVoiceSettings = true;
            if (this.CommonVoice == null)
            {
                this.CommonVoice = new VoiceSettings();
                flag             = true;
            }
            else
            {
                if ((this.CommonVoice.Volume < 0.0) || (this.CommonVoice.Volume > 2.0))
                {
                    this.CommonVoice.Volume = 1f;
                    flag = true;
                }
                if ((this.CommonVoice.Speed < 0.5) || (this.CommonVoice.Speed > 4.0))
                {
                    this.CommonVoice.Speed = 1f;
                    flag = true;
                }
                if ((this.CommonVoice.Pitch < 0.5) || (this.CommonVoice.Pitch > 2.0))
                {
                    this.CommonVoice.Pitch = 1f;
                    flag = true;
                }
                if ((this.CommonVoice.Emphasis < 0.0) || (this.CommonVoice.Emphasis > 2.0))
                {
                    this.CommonVoice.Emphasis = 1f;
                    flag = true;
                }
                if ((this.CommonVoice.MiddlePause < 80) || (this.CommonVoice.MiddlePause > 500))
                {
                    this.CommonVoice.MiddlePause = 150;
                    flag = true;
                }
                if ((this.CommonVoice.LongPause < 100) || (this.CommonVoice.LongPause > 0x7d0))
                {
                    this.CommonVoice.LongPause = 370;
                    flag = true;
                }
                if ((this.CommonVoice.SentencePause < 200) || (this.CommonVoice.SentencePause > 0x2710))
                {
                    this.CommonVoice.SentencePause = 800;
                    flag = true;
                }
            }
            if (this.Voice == null)
            {
                this.Voice = new List <VoiceSettings>();
                flag       = true;
            }
            else
            {
                this.Voice.Clear();
            }
            if (this.Jeita == null)
            {
                this.Jeita = new JeitaSettings();
                flag       = true;
            }
            else
            {
                if (this.Jeita.FemaleVoiceName == null)
                {
                    this.Jeita.FemaleVoiceName = "";
                    flag = true;
                }
                if (this.Jeita.MaleVoiceName == null)
                {
                    this.Jeita.MaleVoiceName = "";
                    flag = true;
                }
                if ((this.Jeita.Sex == null) || ((this.Jeita.Sex != "F") && (this.Jeita.Sex != "M")))
                {
                    this.Jeita.Sex = "F";
                    flag           = true;
                }
                if ((this.Jeita.Volume < 0) || (this.Jeita.Volume > 9))
                {
                    this.Jeita.Volume = 7;
                    flag = true;
                }
                if ((this.Jeita.Speed < 1) || (this.Jeita.Speed > 9))
                {
                    this.Jeita.Speed = 5;
                    flag             = true;
                }
                if ((this.Jeita.Pitch < 1) || (this.Jeita.Pitch > 5))
                {
                    this.Jeita.Pitch = 3;
                    flag             = true;
                }
                if ((this.Jeita.Emphasis < 0) || (this.Jeita.Emphasis > 3))
                {
                    this.Jeita.Emphasis = 2;
                    flag = true;
                }
                if ((this.Jeita.MiddlePause < 80) || (this.Jeita.MiddlePause > 300))
                {
                    this.Jeita.MiddlePause = 100;
                    flag = true;
                }
                if ((this.Jeita.LongPause < 100) || (this.Jeita.LongPause > 0x7d0))
                {
                    this.Jeita.LongPause = 300;
                    flag = true;
                }
                if ((this.Jeita.SentencePause < 300) || (this.Jeita.SentencePause > 0x2710))
                {
                    this.Jeita.SentencePause = 800;
                    flag = true;
                }
            }
            return(!flag);
        }