Skip to content

Commit

Permalink
fix denoise under gate vad, keep state always initd
Browse files Browse the repository at this point in the history
  • Loading branch information
ouwou committed Aug 22, 2023
1 parent 6dcc127 commit 2bc709b
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/audio/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ void capture_data_callback(ma_device *pDevice, void *pOutput, const void *pInput
AudioManager::AudioManager() {
m_ok = true;

#ifdef WITH_RNNOISE
RNNoiseInitialize();
#endif

int err;
m_encoder = opus_encoder_create(48000, 2, OPUS_APPLICATION_VOIP, &err);
if (err != OPUS_OK) {
Expand Down Expand Up @@ -426,13 +430,20 @@ void AudioManager::OnCapturedPCM(const int16_t *pcm, ma_uint32 frames) {
static std::array<float, 480> denoised_L;
static std::array<float, 480> denoised_R;

bool m_rnnoise_passed = false;
#ifdef WITH_RNNOISE
if (m_vad_method == VADMethod::RNNoise || m_enable_noise_suppression) {
m_rnnoise_passed = CheckVADRNNoise(new_pcm.data(), denoised_L.data(), denoised_R.data());
}
#endif

switch (m_vad_method) {
case VADMethod::Gate:
if (!CheckVADVoiceGate()) return;
break;
#ifdef WITH_RNNOISE
case VADMethod::RNNoise:
if (!CheckVADRNNoise(new_pcm.data(), denoised_L.data(), denoised_R.data())) return;
if (!m_rnnoise_passed) return;
break;
#endif
}
Expand Down Expand Up @@ -588,14 +599,6 @@ void AudioManager::SetVADMethod(const std::string &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
if (method == VADMethod::RNNoise) {
RNNoiseInitialize();
} else {
RNNoiseUninitialize();
}
#endif
}

AudioManager::VADMethod AudioManager::GetVADMethod() const {
Expand Down

0 comments on commit 2bc709b

Please sign in to comment.