[PATCH] hackrf: fix bandwidth setting

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/osmocom-sdr@lists.osmocom.org/.

argilo at gmail.com argilo at gmail.com
Fri Jan 1 02:34:51 UTC 2021


From: Clayton Smith <argilo at gmail.com>

The T/R switching code added in ae2253c516bfdc9ae4575ecd61fe0e6cd8608a0d
fails to set custom filter bandwidths because it sets bandwidth and
sample rate in the wrong order. As noted in the documentation for
hackrf_set_sample_rate: "If you want to override the baseband filter
selection, you must do so after setting the sample rate."

To solve this problem I moved the set_bandwidth call after
set_sample_rate. It was also necessary to skip the call if a custom
bandwidth was not requested.
---
 lib/hackrf/hackrf_common.cc | 5 ++++-
 lib/hackrf/hackrf_common.h  | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/hackrf/hackrf_common.cc b/lib/hackrf/hackrf_common.cc
index a6de22aab6..666dc60f84 100644
--- a/lib/hackrf/hackrf_common.cc
+++ b/lib/hackrf/hackrf_common.cc
@@ -37,6 +37,7 @@ hackrf_common::hackrf_common(const std::string &args) :
   _center_freq(0),
   _freq_corr(0),
   _auto_gain(false),
+  _requested_bandwidth(0),
   _bandwidth(0),
   _bias(false),
   _started(false)
@@ -339,6 +340,7 @@ double hackrf_common::set_bandwidth( double bandwidth, size_t chan )
   int ret;
 //  osmosdr::freq_range_t bandwidths = get_bandwidth_range( chan );
 
+  _requested_bandwidth = bandwidth;
   if ( bandwidth == 0.0 ) /* bandwidth of 0 means automatic filter selection */
     bandwidth = _sample_rate * 0.75; /* select narrower filters to prevent aliasing */
 
@@ -411,9 +413,10 @@ bool hackrf_common::get_bias()
 void hackrf_common::start()
 {
   _started = true;
-  set_bandwidth(get_bandwidth());
   set_center_freq(get_center_freq());
   set_sample_rate(get_sample_rate());
+  if (_requested_bandwidth != 0)
+    set_bandwidth(get_bandwidth());
   set_gain(get_gain());
   set_bias(get_bias());
 }
diff --git a/lib/hackrf/hackrf_common.h b/lib/hackrf/hackrf_common.h
index bb553c3bc6..d1ab47b6fb 100644
--- a/lib/hackrf/hackrf_common.h
+++ b/lib/hackrf/hackrf_common.h
@@ -104,6 +104,7 @@ private:
   double _freq_corr;
   bool _auto_gain;
   double _amp_gain;
+  double _requested_bandwidth;
   double _bandwidth;
   bool _bias;
   bool _started;
-- 
2.25.1




More information about the osmocom-sdr mailing list