From dd575ff7c7d271df12765daa01d91d4ef9edd17e Mon Sep 17 00:00:00 2001 From: Mooneer Salem Date: Thu, 5 Sep 2024 22:59:11 -0700 Subject: [PATCH] Disallow sample rates lower than 16000 in audio config. --- src/audio/IAudioEngine.cpp | 2 -- src/main.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/audio/IAudioEngine.cpp b/src/audio/IAudioEngine.cpp index 1723a6f2e..b94661493 100644 --- a/src/audio/IAudioEngine.cpp +++ b/src/audio/IAudioEngine.cpp @@ -24,8 +24,6 @@ int IAudioEngine::StandardSampleRates[] = { - 8000, 9600, - 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, diff --git a/src/main.cpp b/src/main.cpp index 30e85d70b..7d9013306 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3166,6 +3166,44 @@ bool MainFrame::validateSoundCardSetup() "Your %s device cannot be found and may have been removed from your system. Please reattach this device, close this message box and retry. If this fails, go to Tools->Audio Config... to check your settings.", failedDeviceName), wxT("Sound Device Not Found"), wxOK, this); } + else + { + const int MIN_SAMPLE_RATE = 16000; + int failedSampleRate = 0; + + // Validate sample rates + if (wxGetApp().appConfiguration.audioConfiguration.soundCard1In.deviceName != "none" && wxGetApp().appConfiguration.audioConfiguration.soundCard1In.sampleRate < MIN_SAMPLE_RATE) + { + failedDeviceName = wxGetApp().appConfiguration.audioConfiguration.soundCard1In.deviceName.get(); + failedSampleRate = wxGetApp().appConfiguration.audioConfiguration.soundCard1In.sampleRate; + canRun = false; + } + else if (wxGetApp().appConfiguration.audioConfiguration.soundCard1Out.deviceName != "none" && wxGetApp().appConfiguration.audioConfiguration.soundCard1Out.sampleRate < MIN_SAMPLE_RATE) + { + failedDeviceName = wxGetApp().appConfiguration.audioConfiguration.soundCard1Out.deviceName.get(); + failedSampleRate = wxGetApp().appConfiguration.audioConfiguration.soundCard1Out.sampleRate; + canRun = false; + } + else if (wxGetApp().appConfiguration.audioConfiguration.soundCard2In.deviceName != "none" && wxGetApp().appConfiguration.audioConfiguration.soundCard2In.sampleRate < MIN_SAMPLE_RATE) + { + failedDeviceName = wxGetApp().appConfiguration.audioConfiguration.soundCard2In.deviceName.get(); + failedSampleRate = wxGetApp().appConfiguration.audioConfiguration.soundCard2In.sampleRate; + canRun = false; + } + else if (wxGetApp().appConfiguration.audioConfiguration.soundCard2Out.deviceName != "none" && wxGetApp().appConfiguration.audioConfiguration.soundCard2Out.sampleRate < MIN_SAMPLE_RATE) + { + failedDeviceName = wxGetApp().appConfiguration.audioConfiguration.soundCard2Out.deviceName.get(); + failedSampleRate = wxGetApp().appConfiguration.audioConfiguration.soundCard2Out.sampleRate; + canRun = false; + } + + if (!canRun) + { + wxMessageBox(wxString::Format( + "Your %s device is set to use a sample rate of %d, which is less than the minimum of %d. Please go to Tools->Audio Config... to check your settings.", + failedDeviceName, failedSampleRate, MIN_SAMPLE_RATE), wxT("Sample Rate Too Low"), wxOK, this); + } + } engine->stop(); engine->setOnEngineError(nullptr, nullptr);