make vad method a setting and tie it to combobox

This commit is contained in:
ouwou
2023-07-23 01:01:45 -04:00
parent 203e566919
commit 60e3f73324
6 changed files with 44 additions and 18 deletions

View File

@@ -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() {

View File

@@ -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

View File

@@ -75,6 +75,7 @@ public:
RNNoise,
};
void SetVADMethod(const std::string &method);
void SetVADMethod(VADMethod method);
private:

View File

@@ -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

View File

@@ -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 };
};

View File

@@ -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");
#else
m_vad_combo.set_active_id("gate");
#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");
#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>();