mirror of
				https://github.com/cjcliffe/CubicSDR.git
				synced 2025-11-03 21:20:21 -05:00 
			
		
		
		
	#513 Workaround in case the number of samples rates is too much to be handled by the menu, decimate to 25 max.
This commit is contained in:
		
							parent
							
								
									230a87d8df
								
							
						
					
					
						commit
						89d12ef4e3
					
				@ -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
 | 
			
		||||
@ -2,6 +2,7 @@
 | 
			
		||||
// SPDX-License-Identifier: GPL-2.0+
 | 
			
		||||
 | 
			
		||||
#include "SDRDeviceInfo.h"
 | 
			
		||||
#include "CubicSDRDefs.h"
 | 
			
		||||
#include <cstdlib>
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
 | 
			
		||||
@ -179,12 +180,38 @@ bool SDRDeviceInfo::hasCORR(int direction, size_t channel) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<long> SDRDeviceInfo::getSampleRates(int direction, size_t channel) {
 | 
			
		||||
 | 
			
		||||
    SoapySDR::Device *dev = getSoapyDevice();
 | 
			
		||||
 | 
			
		||||
	size_t nbMaxDifferentRates = DEVICE_SAMPLE_RATES_MAX_NB;
 | 
			
		||||
    
 | 
			
		||||
    std::vector<long> result;
 | 
			
		||||
 | 
			
		||||
	//the original list returned from the driver:
 | 
			
		||||
    std::vector<double> 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<std::string> gainNames = dev->listGains(direction, channel);
 | 
			
		||||
    
 | 
			
		||||
	std::map<std::string, SoapySDR::Range> gainMap;
 | 
			
		||||
    
 | 
			
		||||
    for (std::string gname : gainNames) {
 | 
			
		||||
 | 
			
		||||
        gainMap[gname] = dev->getGainRange(direction, channel, gname);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user