diff --git a/src/CubicSDRDefs.h b/src/CubicSDRDefs.h index e5cc4ca..3beb96b 100644 --- a/src/CubicSDRDefs.h +++ b/src/CubicSDRDefs.h @@ -59,3 +59,7 @@ const char filePathSeparator = //Represents the amount of time to process in the FFT distributor. #define FFT_DISTRIBUTOR_BUFFER_IN_SECONDS 0.250 + +//The maximum number of listed sample rates for a device, to be able to handle +//devices returning an insane amount because they have quasi-continuous ranges (UHD...) +#define DEVICE_SAMPLE_RATES_MAX_NB 25 \ No newline at end of file diff --git a/src/sdr/SDRDeviceInfo.cpp b/src/sdr/SDRDeviceInfo.cpp index 8542a9a..6bf415b 100644 --- a/src/sdr/SDRDeviceInfo.cpp +++ b/src/sdr/SDRDeviceInfo.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-2.0+ #include "SDRDeviceInfo.h" +#include "CubicSDRDefs.h" #include #include @@ -179,14 +180,40 @@ bool SDRDeviceInfo::hasCORR(int direction, size_t channel) { } std::vector SDRDeviceInfo::getSampleRates(int direction, size_t channel) { + SoapySDR::Device *dev = getSoapyDevice(); + + size_t nbMaxDifferentRates = DEVICE_SAMPLE_RATES_MAX_NB; std::vector result; + + //the original list returned from the driver: std::vector sampleRates = dev->listSampleRates(direction, channel); - for (double si : sampleRates) { - result.push_back((long)si); - } - + + //be paranoid, sort by increasing rates... + std::sort(sampleRates.begin(), sampleRates.end(), [](double a, double b) -> bool { return a < b; }); + + //if sampleRates.size() > nbMaxDifferentRates, decimate this number to only return nbMaxDifferentRates sample + //rates values. + size_t sampleRateSelectionStep = 1; + + if (sampleRates.size() / nbMaxDifferentRates >= 2) { + + sampleRateSelectionStep = sampleRates.size() / nbMaxDifferentRates; + } + + for (size_t i = 0; sampleRateSelectionStep * i < sampleRates.size(); i++) { + + //convert to longs... + result.push_back((long)sampleRates[sampleRateSelectionStep * i]); + } + + //always include the biggest value: + if ((long)sampleRates.back() > result.back()) { + + result.push_back((long)sampleRates.back()); + } + return result; } @@ -230,10 +257,13 @@ long SDRDeviceInfo::getSampleRateNear(int direction, size_t channel, long sample SDRRangeMap SDRDeviceInfo::getGains(int direction, size_t channel) { SoapySDR::Device *dev = getSoapyDevice(); - std::vector gainNames = dev->listGains(direction, channel); - std::map gainMap; + + std::vector gainNames = dev->listGains(direction, channel); + + std::map gainMap; for (std::string gname : gainNames) { + gainMap[gname] = dev->getGainRange(direction, channel, gname); }