From 9dda9e1efc2ff5b820438524c666900f93fe3a72 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sat, 18 Mar 2017 09:30:26 +0100 Subject: SDR: Add option to set IF bandwidth. If not defined, sampling rate is used. --- src/common/soapy.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/common/soapy.c') diff --git a/src/common/soapy.c b/src/common/soapy.c index 76e213e..1f56456 100644 --- a/src/common/soapy.c +++ b/src/common/soapy.c @@ -35,9 +35,9 @@ static double samplerate; static long long rx_count = 0; static long long tx_count = 0; -int soapy_open(const char *device_args, double tx_frequency, double rx_frequency, double rate, double rx_gain, double tx_gain) +int soapy_open(const char *device_args, double tx_frequency, double rx_frequency, double rate, double rx_gain, double tx_gain, double bandwidth) { - double got_frequency, got_rate, got_gain; + double got_frequency, got_rate, got_gain, got_bandwidth; size_t channel = 0; char *arg_string = strdup(device_args), *key, *val; SoapySDRKwargs args; @@ -144,6 +144,32 @@ int soapy_open(const char *device_args, double tx_frequency, double rx_frequency return -EINVAL; } + /* set bandwidth */ + if (SoapySDRDevice_setBandwidth(sdr, SOAPY_SDR_TX, channel, bandwidth) != 0) { + PDEBUG(DUHD, DEBUG_ERROR, "Failed to set TX bandwidth to %.0f Hz\n", bandwidth); + soapy_close(); + return -EIO; + } + if (SoapySDRDevice_setBandwidth(sdr, SOAPY_SDR_RX, channel, bandwidth) != 0) { + PDEBUG(DUHD, DEBUG_ERROR, "Failed to set RX bandwidth to %.0f Hz\n", bandwidth); + soapy_close(); + return -EIO; + } + + /* see what bandwidth actually is */ + got_bandwidth = SoapySDRDevice_getBandwidth(sdr, SOAPY_SDR_TX, channel); + if (got_bandwidth != bandwidth) { + PDEBUG(DUHD, DEBUG_ERROR, "Given TX bandwidth %.0f Hz is not supported, try %0.f Hz\n", bandwidth, got_bandwidth); + soapy_close(); + return -EINVAL; + } + got_bandwidth = SoapySDRDevice_getBandwidth(sdr, SOAPY_SDR_RX, channel); + if (got_bandwidth != bandwidth) { + PDEBUG(DUHD, DEBUG_ERROR, "Given RX bandwidth %.0f Hz is not supported, try %0.f Hz\n", bandwidth, got_bandwidth); + soapy_close(); + return -EINVAL; + } + /* set up streamer */ if (SoapySDRDevice_setupStream(sdr, &txStream, SOAPY_SDR_TX, SOAPY_SDR_CF32, &channel, 1, NULL) != 0) { PDEBUG(DUHD, DEBUG_ERROR, "Failed to set TX streamer args\n"); -- cgit v1.2.3