slight refactor, show rnnoise vad prob in meter when selected

This commit is contained in:
ouwou
2023-07-23 01:44:36 -04:00
parent 07fc439eb7
commit dc92fef708
4 changed files with 50 additions and 16 deletions

View File

@@ -487,8 +487,8 @@ bool AudioManager::CheckVADRNNoise(const int16_t *pcm) {
for (size_t i = 0; i < 480; i++) {
rnnoise_input[i] = static_cast<float>(pcm[i * 2]);
}
float vad_prob = rnnoise_process_frame(m_rnnoise, denoised, rnnoise_input);
return vad_prob > m_prob_threshold;
m_vad_prob = rnnoise_process_frame(m_rnnoise, denoised, rnnoise_input);
return m_vad_prob > m_prob_threshold;
}
void AudioManager::RNNoiseInitialize() {
@@ -564,6 +564,14 @@ void AudioManager::SetVADMethod(VADMethod method) {
#endif
}
AudioManager::VADMethod AudioManager::GetVADMethod() const {
return m_vad_method;
}
float AudioManager::GetCurrentVADProbability() const {
return m_vad_prob;
}
AudioManager::type_signal_opus_packet AudioManager::signal_opus_packet() {
return m_signal_opus_packet;
}

View File

@@ -77,6 +77,8 @@ public:
void SetVADMethod(const std::string &method);
void SetVADMethod(VADMethod method);
VADMethod GetVADMethod() const;
float GetCurrentVADProbability() const;
private:
void OnCapturedPCM(const int16_t *pcm, ma_uint32 frames);
@@ -129,6 +131,7 @@ private:
std::atomic<double> m_capture_gate = 0.0;
std::atomic<double> m_capture_gain = 1.0;
std::atomic<double> m_prob_threshold = 0.5;
std::atomic<float> m_vad_prob = 0.0;
std::unordered_set<uint32_t> m_muted_ssrcs;
std::unordered_map<uint32_t, double> m_volume_ssrc;

View File

@@ -115,15 +115,23 @@ VoiceWindow::VoiceWindow(Snowflake channel_id)
m_scroll.set_hexpand(true);
m_scroll.set_vexpand(true);
m_capture_volume.SetShowTick(true);
m_vad_value.SetShowTick(true);
m_capture_gate.set_range(0.0, 100.0);
m_capture_gate.set_value_pos(Gtk::POS_LEFT);
m_capture_gate.set_value(audio.GetCaptureGate() * 100.0);
m_capture_gate.signal_value_changed().connect([this]() {
const double val = m_capture_gate.get_value() * 0.01;
m_signal_gate.emit(val);
m_capture_volume.SetTick(val);
m_vad_param.set_range(0.0, 100.0);
m_vad_param.set_value_pos(Gtk::POS_LEFT);
m_vad_param.set_value(audio.GetCaptureGate() * 100.0);
m_vad_param.signal_value_changed().connect([this]() {
const double val = m_vad_param.get_value() * 0.01;
switch (Abaddon::Get().GetAudio().GetVADMethod()) {
case AudioManager::VADMethod::Gate:
m_signal_gate.emit(val);
m_vad_value.SetTick(val);
break;
#ifdef WITH_RNNOISE
case AudioManager::VADMethod::RNNoise:
break;
#endif
};
});
m_capture_gain.set_range(0.0, 200.0);
@@ -204,8 +212,8 @@ VoiceWindow::VoiceWindow(Snowflake channel_id)
m_controls.add(m_deafen);
m_main.add(m_menu_bar);
m_main.add(m_controls);
m_main.add(m_capture_volume);
m_main.add(m_capture_gate);
m_main.add(m_vad_value);
m_main.add(m_vad_param);
m_main.add(m_capture_gain);
m_main.add(m_scroll);
m_main.add(m_vad_combo);
@@ -249,11 +257,22 @@ void VoiceWindow::OnDeafenChanged() {
}
bool VoiceWindow::UpdateVoiceMeters() {
m_capture_volume.SetVolume(Abaddon::Get().GetAudio().GetCaptureVolumeLevel());
auto &audio = Abaddon::Get().GetAudio();
switch (audio.GetVADMethod()) {
case AudioManager::VADMethod::Gate:
m_vad_value.SetVolume(audio.GetCaptureVolumeLevel());
break;
#ifdef WITH_RNNOISE
case AudioManager::VADMethod::RNNoise:
m_vad_value.SetVolume(audio.GetCurrentVADProbability());
break;
#endif
}
for (auto [id, row] : m_rows) {
const auto ssrc = Abaddon::Get().GetDiscordClient().GetSSRCOfUser(id);
if (ssrc.has_value()) {
row->SetVolumeMeter(Abaddon::Get().GetAudio().GetSSRCVolumeLevel(*ssrc));
row->SetVolumeMeter(audio.GetSSRCVolumeLevel(*ssrc));
}
}
return true;

View File

@@ -43,8 +43,12 @@ private:
Gtk::ScrolledWindow m_scroll;
Gtk::ListBox m_user_list;
VolumeMeter m_capture_volume;
Gtk::Scale m_capture_gate;
// Shows volume for gate VAD method
// Shows probability for RNNoise VAD method
VolumeMeter m_vad_value;
// Volume threshold for gate VAD method
// VAD probability threshold for RNNoise VAD method
Gtk::Scale m_vad_param;
Gtk::Scale m_capture_gain;
Gtk::ComboBoxText m_vad_combo;