diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-07-23 01:01:45 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-07-23 01:01:45 -0400 |
commit | 60e3f733241a5524610450adee897c6aca02da42 (patch) | |
tree | fc9b3a317ec88b6f99ecd00cdd03d447b8fad56d /src | |
parent | 203e5669199982533900d3b2ad9a8ba12903852c (diff) | |
download | abaddon-portaudio-60e3f733241a5524610450adee897c6aca02da42.tar.gz abaddon-portaudio-60e3f733241a5524610450adee897c6aca02da42.zip |
make vad method a setting and tie it to combobox
Diffstat (limited to 'src')
-rw-r--r-- | src/abaddon.cpp | 9 | ||||
-rw-r--r-- | src/audio/manager.cpp | 24 | ||||
-rw-r--r-- | src/audio/manager.hpp | 1 | ||||
-rw-r--r-- | src/settings.cpp | 4 | ||||
-rw-r--r-- | src/settings.hpp | 7 | ||||
-rw-r--r-- | src/windows/voicewindow.cpp | 15 |
6 files changed, 43 insertions, 17 deletions
diff --git a/src/abaddon.cpp b/src/abaddon.cpp index 2be54ba..fdc4023 100644 --- a/src/abaddon.cpp +++ b/src/abaddon.cpp @@ -23,11 +23,11 @@ #include "remoteauth/remoteauthdialog.hpp" #ifdef WITH_LIBHANDY - #include <handy.h> +#include <handy.h> #endif #ifdef _WIN32 - #pragma comment(lib, "crypt32.lib") +#pragma comment(lib, "crypt32.lib") #endif Abaddon::Abaddon() @@ -67,7 +67,7 @@ Abaddon::Abaddon() if (!accessible) m_channels_requested.erase(id); }); - if (GetSettings().Prefetch) + if (GetSettings().Prefetch) { m_discord.signal_message_create().connect([this](const Message &message) { if (message.Author.HasAvatar()) m_img_mgr.Prefetch(message.Author.GetAvatarURL()); @@ -76,6 +76,9 @@ Abaddon::Abaddon() m_img_mgr.Prefetch(attachment.ProxyURL); } }); + } + + m_audio.SetVADMethod(GetSettings().VAD); } Abaddon &Abaddon::Get() { diff --git a/src/audio/manager.cpp b/src/audio/manager.cpp index 48df603..bdb7922 100644 --- a/src/audio/manager.cpp +++ b/src/audio/manager.cpp @@ -83,12 +83,6 @@ AudioManager::AudioManager() { Enumerate(); -#ifdef WITH_RNNOISE - SetVADMethod(VADMethod::RNNoise); -#else - SetVADMethod(VADMethod::Gate); -#endif - m_playback_config = ma_device_config_init(ma_device_type_playback); m_playback_config.playback.format = ma_format_f32; m_playback_config.playback.channels = 2; @@ -540,7 +534,25 @@ uint32_t AudioManager::GetRTPTimestamp() const noexcept { return m_rtp_timestamp; } +void AudioManager::SetVADMethod(const std::string &method) { + spdlog::get("audio")->debug("Setting VAD method to {}", method); + if (method == "gate") { + SetVADMethod(VADMethod::Gate); + } else if (method == "rnnoise") { +#ifdef WITH_RNNOISE + SetVADMethod(VADMethod::RNNoise); +#else + SetVADMethod(VADMethod::Gate); + spdlog::get("audio")->error("Tried to set RNNoise VAD method with support disabled"); +#endif + } else { + SetVADMethod(VADMethod::Gate); + spdlog::get("audio")->error("Tried to set unknown VAD method {}", method); + } +} + void AudioManager::SetVADMethod(VADMethod method) { + spdlog::get("audio")->debug("Setting VAD method to enum {}", static_cast<int>(method)); m_vad_method = method; #ifdef WITH_RNNOISE diff --git a/src/audio/manager.hpp b/src/audio/manager.hpp index ec62fed..2e7d087 100644 --- a/src/audio/manager.hpp +++ b/src/audio/manager.hpp @@ -75,6 +75,7 @@ public: RNNoise, }; + void SetVADMethod(const std::string &method); void SetVADMethod(VADMethod method); private: diff --git a/src/settings.cpp b/src/settings.cpp index 0b868da..601205a 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -4,7 +4,7 @@ #include <glibmm/miscutils.h> #ifdef WITH_KEYCHAIN - #include <keychain/keychain.h> +#include <keychain/keychain.h> #endif const std::string KeychainPackage = "com.github.uowuo.abaddon"; @@ -70,6 +70,7 @@ void SettingsManager::ReadSettings() { SMSTR("style", "unreadcolor", UnreadIndicatorColor); SMBOOL("notifications", "enabled", NotificationsEnabled); SMBOOL("notifications", "playsound", NotificationsPlaySound); + SMSTR("voice", "vad", VAD); SMBOOL("windows", "hideconsole", HideConsole); #ifdef WITH_KEYCHAIN @@ -154,6 +155,7 @@ void SettingsManager::Close() { SMSTR("style", "unreadcolor", UnreadIndicatorColor); SMBOOL("notifications", "enabled", NotificationsEnabled); SMBOOL("notifications", "playsound", NotificationsPlaySound); + SMSTR("voice", "vad", VAD); SMBOOL("windows", "hideconsole", HideConsole); #ifdef WITH_KEYCHAIN diff --git a/src/settings.hpp b/src/settings.hpp index 40cb1d3..0d2e68b 100644 --- a/src/settings.hpp +++ b/src/settings.hpp @@ -53,6 +53,13 @@ public: #endif bool NotificationsPlaySound { true }; + // [voice] +#ifdef WITH_RNNOISE + std::string VAD { "rnnoise" }; +#else + std::string VAD { "gate" }; +#endif + // [windows] bool HideConsole { false }; }; diff --git a/src/windows/voicewindow.cpp b/src/windows/voicewindow.cpp index f411f80..01e7b9b 100644 --- a/src/windows/voicewindow.cpp +++ b/src/windows/voicewindow.cpp @@ -140,17 +140,18 @@ VoiceWindow::VoiceWindow(Snowflake channel_id) m_vad_combo.append("gate", "Gate"); #ifdef WITH_RNNOISE m_vad_combo.append("rnnoise", "RNNoise"); - m_vad_combo.set_active_id("rnnoise"); +#endif + if (!m_vad_combo.set_active_id(Abaddon::Get().GetSettings().VAD)) { +#ifdef WITH_RNNOISE + m_vad_combo.set_active_id("rnnoise"); #else - m_vad_combo.set_active_id("gate"); + m_vad_combo.set_active_id("gate"); #endif + } m_vad_combo.signal_changed().connect([this]() { const auto id = m_vad_combo.get_active_id(); - if (id == "gate") { - Abaddon::Get().GetAudio().SetVADMethod(AudioManager::VADMethod::Gate); - } else if (id == "rnnoise") { - Abaddon::Get().GetAudio().SetVADMethod(AudioManager::VADMethod::RNNoise); - } + Abaddon::Get().GetAudio().SetVADMethod(id); + Abaddon::Get().GetSettings().VAD = id; }); auto *playback_renderer = Gtk::make_managed<Gtk::CellRendererText>(); |