From aaa1246d7de6715a49aa145fb8fec45e1bfc0185 Mon Sep 17 00:00:00 2001 From: Maximilian Wittfeld Date: Thu, 31 Oct 2024 23:18:03 +0100 Subject: [PATCH] fix(voip-mumble): nullptr check This fixes a nullptr exception when trying to write to the Audio Processing Module while the audioCaptureClient is invalid. We now also apply the last voice intent mode to the new audio device instead of the default ('speech') mode. --- .../voip-mumble/src/MumbleAudioInput.cpp | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/code/components/voip-mumble/src/MumbleAudioInput.cpp b/code/components/voip-mumble/src/MumbleAudioInput.cpp index f29f9e2bfc..1494c1f235 100644 --- a/code/components/voip-mumble/src/MumbleAudioInput.cpp +++ b/code/components/voip-mumble/src/MumbleAudioInput.cpp @@ -139,22 +139,26 @@ void MumbleAudioInput::ThreadFunc() if (g_curInputIntentMode != g_lastIntentMode) { - switch (g_curInputIntentMode) - { - case InputIntentMode::MUSIC: - { - m_apm->noise_suppression()->Enable(false); - m_apm->high_pass_filter()->Enable(false); - break; - } - case InputIntentMode::SPEECH: - default: + if (m_apm) { - m_apm->noise_suppression()->Enable(true); - m_apm->high_pass_filter()->Enable(true); - break; + switch (g_curInputIntentMode) + { + case InputIntentMode::MUSIC: + { + m_apm->noise_suppression()->Enable(false); + m_apm->high_pass_filter()->Enable(false); + break; + } + case InputIntentMode::SPEECH: + default: + { + m_apm->noise_suppression()->Enable(true); + m_apm->high_pass_filter()->Enable(true); + break; + } + }; } - }; + g_lastIntentMode = g_curInputIntentMode; } @@ -705,10 +709,12 @@ void MumbleAudioInput::InitializeAudioDevice() m_apm->Initialize(pconfig); - m_apm->high_pass_filter()->Enable(true); - m_apm->echo_cancellation()->Enable(false); - m_apm->noise_suppression()->Enable(true); + const bool isVoiceIntent = g_curInputIntentMode == InputIntentMode::SPEECH; + m_apm->high_pass_filter()->Enable(isVoiceIntent); + m_apm->noise_suppression()->Enable(isVoiceIntent); m_apm->noise_suppression()->set_level(webrtc::NoiseSuppression::kHigh); + + m_apm->echo_cancellation()->Enable(false); m_apm->level_estimator()->Enable(true); m_apm->voice_detection()->set_likelihood(ConvertLikelihood(m_likelihood)); //m_apm->voice_detection()->set_frame_size_ms(10);