aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/constants.hpp.in7
-rw-r--r--host/lib/utils/gain_group.cpp31
-rw-r--r--host/lib/utils/paths.cpp12
3 files changed, 35 insertions, 15 deletions
diff --git a/host/lib/constants.hpp.in b/host/lib/constants.hpp.in
index 295c8f16c..aa51e558c 100644
--- a/host/lib/constants.hpp.in
+++ b/host/lib/constants.hpp.in
@@ -21,8 +21,9 @@
#include <uhd/config.hpp>
#include <string>
-static const std::string UHD_VERSION_STRING = "@CPACK_PACKAGE_VERSION@";
-static const std::string UHD_INSTALL_PREFIX = "@CMAKE_INSTALL_PREFIX@";
-static const std::string UHD_PKG_DATA_DIR = "@PKG_DATA_DIR@";
+//these should be pre-processor macros to avoid static initialization issues
+#define UHD_VERSION_STRING "@CPACK_PACKAGE_VERSION@"
+#define UHD_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@"
+#define UHD_PKG_DATA_DIR "@PKG_DATA_DIR@"
#endif /* INCLUDED_LIBUHD_CONSTANTS_HPP */
diff --git a/host/lib/utils/gain_group.cpp b/host/lib/utils/gain_group.cpp
index c113719c8..078fe56b2 100644
--- a/host/lib/utils/gain_group.cpp
+++ b/host/lib/utils/gain_group.cpp
@@ -35,6 +35,25 @@ static bool compare_by_step_size(
return fcns.at(rhs).get_range().step > fcns.at(lhs).get_range().step;
}
+/*!
+ * Get a multiple of step with the following relation:
+ * result = step*floor(num/step)
+ *
+ * Due to small floating-point inaccuracies:
+ * num = n*step + e, where e is a small inaccuracy.
+ * When e is negative, floor would yeild (n-1)*step,
+ * despite that n*step is really the desired result.
+ * This function is designed to mitigate that issue.
+ *
+ * \param num the number to approximate
+ * \param step the step size to round with
+ * \param e the small inaccuracy to account for
+ * \return a multiple of step approximating num
+ */
+template <typename T> static T floor_step(T num, T step, T e = T(0.001)){
+ return step*int(num/step + e);
+}
+
/***********************************************************************
* gain group implementation
**********************************************************************/
@@ -82,9 +101,9 @@ public:
float gain_left_to_distribute = gain;
BOOST_FOREACH(const gain_fcns_t &fcns, all_fcns){
const gain_range_t range = fcns.get_range();
- gain_bucket.push_back(
- max_step*int(std::clip(gain_left_to_distribute, range.min, range.max)/max_step)
- );
+ gain_bucket.push_back(floor_step(std::clip(
+ gain_left_to_distribute, range.min, range.max
+ ), max_step));
gain_left_to_distribute -= gain_bucket.back();
}
@@ -106,9 +125,9 @@ public:
//fill in the largest step sizes first that are less than the remainder
BOOST_FOREACH(size_t i, indexes_step_size_dec){
const gain_range_t range = all_fcns.at(i).get_range();
- float additional_gain = range.step*int(
- std::clip(gain_bucket.at(i) + gain_left_to_distribute, range.min, range.max
- )/range.step) - gain_bucket.at(i);
+ float additional_gain = floor_step(std::clip(
+ gain_bucket.at(i) + gain_left_to_distribute, range.min, range.max
+ ), range.step) - gain_bucket.at(i);
gain_bucket.at(i) += additional_gain;
gain_left_to_distribute -= additional_gain;
}
diff --git a/host/lib/utils/paths.cpp b/host/lib/utils/paths.cpp
index 0805a44fe..4029bd989 100644
--- a/host/lib/utils/paths.cpp
+++ b/host/lib/utils/paths.cpp
@@ -60,12 +60,14 @@ static std::vector<fs::path> get_env_paths(const std::string &var_name){
//split the path at the path separators
std::vector<std::string> path_strings;
- boost::split(path_strings, var_value, boost::is_any_of(env_path_sep));
+ if (not var_value.empty()) boost::split(//dont split empty strings
+ path_strings, var_value, boost::is_any_of(env_path_sep)
+ );
//convert to filesystem path, filter blank paths
std::vector<fs::path> paths;
BOOST_FOREACH(std::string &path_string, path_strings){
- if (path_string.size() == 0) continue;
+ if (path_string.empty()) continue;
paths.push_back(fs::system_complete(path_string));
}
return paths;
@@ -74,17 +76,15 @@ static std::vector<fs::path> get_env_paths(const std::string &var_name){
/***********************************************************************
* Get a list of special purpose paths
**********************************************************************/
-static const fs::path pkg_data_path = fs::path(UHD_INSTALL_PREFIX) / UHD_PKG_DATA_DIR;
-
std::vector<fs::path> get_image_paths(void){
std::vector<fs::path> paths = get_env_paths("UHD_IMAGE_PATH");
- paths.push_back(pkg_data_path / "images");
+ paths.push_back(fs::path(UHD_INSTALL_PREFIX) / UHD_PKG_DATA_DIR / "images");
return paths;
}
std::vector<fs::path> get_module_paths(void){
std::vector<fs::path> paths = get_env_paths("UHD_MODULE_PATH");
- paths.push_back(pkg_data_path / "modules");
+ paths.push_back(fs::path(UHD_INSTALL_PREFIX) / UHD_PKG_DATA_DIR / "modules");
return paths;
}