From 4dade2a7090a615df3b7fab01fecb58f9f5770f4 Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 2 Jul 2025 00:05:22 +0200 Subject: [PATCH] Try to find the correct available audio sample rates in Qt5 --- sdrbase/audio/audiodeviceinfo.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/sdrbase/audio/audiodeviceinfo.cpp b/sdrbase/audio/audiodeviceinfo.cpp index 955146653..5c18ea1e2 100644 --- a/sdrbase/audio/audiodeviceinfo.cpp +++ b/sdrbase/audio/audiodeviceinfo.cpp @@ -60,7 +60,21 @@ QList AudioDeviceInfo::supportedSampleRates() const #else QList AudioDeviceInfo::supportedSampleRates() const { - return m_deviceInfo.supportedSampleRates(); + QList reportedSampleRates = m_deviceInfo.supportedSampleRates(); + reportedSampleRates.append({96000, 192000, 384000}); // Add some common rates that may not be in the list + QList sampleRates; + + for (auto sampleRate : reportedSampleRates) // Retain the sample rates that are supported by the device + { + QAudioFormat format = m_deviceInfo.preferredFormat(); + format.setSampleRate(sampleRate); + + if (m_deviceInfo.isFormatSupported(format)) { + sampleRates.append(sampleRate); + } + } + + return sampleRates; } #endif