summaryrefslogtreecommitdiffstats
path: root/host/lib/gain_handler.cpp
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-03-12 16:01:01 -0800
committerJosh Blum <josh@joshknows.com>2010-03-12 16:01:01 -0800
commit2147c5f61c2eb6ef1a68419d7b1041a54cbb14a2 (patch)
tree48dbcb58924a3c547979cb4a95a5de35278aeec1 /host/lib/gain_handler.cpp
parentdaed43a8a873ad5cc16ac8a3eb6db5a8fe126fa5 (diff)
downloaduhd-2147c5f61c2eb6ef1a68419d7b1041a54cbb14a2.tar.gz
uhd-2147c5f61c2eb6ef1a68419d7b1041a54cbb14a2.tar.bz2
uhd-2147c5f61c2eb6ef1a68419d7b1041a54cbb14a2.zip
Removed freq min and max and gain min, max, and step...
replaced it with gain and freq range tuples. This simplifies the api calls and subdev properties.
Diffstat (limited to 'host/lib/gain_handler.cpp')
-rw-r--r--host/lib/gain_handler.cpp98
1 files changed, 38 insertions, 60 deletions
diff --git a/host/lib/gain_handler.cpp b/host/lib/gain_handler.cpp
index 8f840ae7f..7eb87558c 100644
--- a/host/lib/gain_handler.cpp
+++ b/host/lib/gain_handler.cpp
@@ -26,23 +26,13 @@
using namespace uhd;
/***********************************************************************
- * helper functions
- **********************************************************************/
-static gain_t gain_max(gain_t a, gain_t b){
- return std::max(a, b);
-}
-static gain_t gain_sum(gain_t a, gain_t b){
- return std::sum(a, b);
-}
-
-/***********************************************************************
* gain handler implementation interface
**********************************************************************/
class gain_handler_impl : public gain_handler{
public:
gain_handler_impl(
const wax::obj &link,
- const gain_props_t &gain_props,
+ const props_t &props,
is_equal_t is_equal
);
~gain_handler_impl(void);
@@ -51,15 +41,15 @@ public:
private:
wax::obj _link;
- gain_props_t _gain_props;
+ props_t _props;
is_equal_t _is_equal;
prop_names_t get_gain_names(void);
- std::vector<gain_t> get_gains(const wax::obj &prop_key);
gain_t get_overall_gain_val(void);
- gain_t get_overall_gain_min(void);
- gain_t get_overall_gain_max(void);
- gain_t get_overall_gain_step(void);
+ gain_range_t get_overall_gain_range(void);
+ template <class T> T get_named_prop(const wax::obj &prop, const std::string &name){
+ return wax::cast<T>(_link[named_prop_t(prop, name)]);
+ }
};
/***********************************************************************
@@ -67,26 +57,26 @@ private:
**********************************************************************/
gain_handler::sptr gain_handler::make(
const wax::obj &link,
- const gain_props_t &gain_props,
+ const props_t &props,
is_equal_t is_equal
){
- return sptr(new gain_handler_impl(link, gain_props, is_equal));
+ return sptr(new gain_handler_impl(link, props, is_equal));
}
/***********************************************************************
* gain handler implementation methods
**********************************************************************/
-gain_handler::gain_props_t::gain_props_t(void){
+gain_handler::props_t::props_t(void){
/* NOP */
}
gain_handler_impl::gain_handler_impl(
const wax::obj &link,
- const gain_props_t &gain_props,
+ const props_t &props,
is_equal_t is_equal
){
_link = link;
- _gain_props = gain_props;
+ _props = props;
_is_equal = is_equal;
}
@@ -95,31 +85,28 @@ gain_handler_impl::~gain_handler_impl(void){
}
prop_names_t gain_handler_impl::get_gain_names(void){
- return wax::cast<prop_names_t>(_link[_gain_props.gain_names_prop]);
+ return wax::cast<prop_names_t>(_link[_props.names]);
}
-std::vector<gain_t> gain_handler_impl::get_gains(const wax::obj &prop_key){
- std::vector<gain_t> gains;
+gain_t gain_handler_impl::get_overall_gain_val(void){
+ gain_t gain_val = 0;
BOOST_FOREACH(std::string name, get_gain_names()){
- gains.push_back(wax::cast<gain_t>(_link[named_prop_t(prop_key, name)]));
+ gain_val += get_named_prop<gain_t>(_props.value, name);
}
- return gains;
-}
-
-gain_t gain_handler_impl::get_overall_gain_val(void){
- return std::reduce<gain_t>(get_gains(_gain_props.gain_val_prop), gain_sum);
-}
-
-gain_t gain_handler_impl::get_overall_gain_min(void){
- return std::reduce<gain_t>(get_gains(_gain_props.gain_min_prop), gain_sum);
-}
-
-gain_t gain_handler_impl::get_overall_gain_max(void){
- return std::reduce<gain_t>(get_gains(_gain_props.gain_max_prop), gain_sum);
+ return gain_val;
}
-gain_t gain_handler_impl::get_overall_gain_step(void){
- return std::reduce<gain_t>(get_gains(_gain_props.gain_step_prop), gain_max);
+gain_range_t gain_handler_impl::get_overall_gain_range(void){
+ gain_t gain_min = 0, gain_max = 0, gain_step = 0;
+ BOOST_FOREACH(std::string name, get_gain_names()){
+ gain_t gain_min_tmp, gain_max_tmp, gain_step_tmp;
+ boost::tie(gain_min_tmp, gain_max_tmp, gain_step_tmp) = \
+ get_named_prop<gain_range_t>(_props.range, name);
+ gain_min += gain_min_tmp;
+ gain_max += gain_max_tmp;
+ gain_step = std::max(gain_step, gain_step_tmp);
+ }
+ return gain_range_t(gain_min, gain_max, gain_step);
}
/***********************************************************************
@@ -135,23 +122,13 @@ bool gain_handler_impl::intercept_get(const wax::obj &key_, wax::obj &val){
return false;
}
- if (_is_equal(key, _gain_props.gain_val_prop)){
+ if (_is_equal(key, _props.value)){
val = get_overall_gain_val();
return true;
}
- if (_is_equal(key, _gain_props.gain_min_prop)){
- val = get_overall_gain_min();
- return true;
- }
-
- if (_is_equal(key, _gain_props.gain_max_prop)){
- val = get_overall_gain_max();
- return true;
- }
-
- if (_is_equal(key, _gain_props.gain_step_prop)){
- val = get_overall_gain_step();
+ if (_is_equal(key, _props.range)){
+ val = get_overall_gain_range();
return true;
}
@@ -166,15 +143,16 @@ bool gain_handler_impl::intercept_set(const wax::obj &key_, const wax::obj &val)
boost::tie(key, name) = extract_named_prop(key_);
//not a gain value key... dont handle
- if (not _is_equal(key, _gain_props.gain_val_prop)) return false;
+ if (not _is_equal(key, _props.value)) return false;
gain_t gain_val = wax::cast<gain_t>(val);
//not a wildcard... dont handle (but check name and range)
if (name != ""){
assert_has(get_gain_names(), name, "gain name");
- gain_t gain_min = wax::cast<gain_t>(_link[named_prop_t(_gain_props.gain_min_prop, name)]);
- gain_t gain_max = wax::cast<gain_t>(_link[named_prop_t(_gain_props.gain_max_prop, name)]);
+ gain_t gain_min, gain_max, gain_step;
+ boost::tie(gain_min, gain_max, gain_step) = \
+ get_named_prop<gain_range_t>(_props.range, name);
if (gain_val > gain_max or gain_val < gain_min) throw std::range_error(str(
boost::format("A value of %f for gain %s is out of range of (%f, %f)")
% gain_val % name % gain_min % gain_max
@@ -185,16 +163,16 @@ bool gain_handler_impl::intercept_set(const wax::obj &key_, const wax::obj &val)
//set the overall gain
BOOST_FOREACH(std::string name, get_gain_names()){
//get the min, max, step for this gain name
- gain_t gain_min = wax::cast<gain_t>(_link[named_prop_t(_gain_props.gain_min_prop, name)]);
- gain_t gain_max = wax::cast<gain_t>(_link[named_prop_t(_gain_props.gain_max_prop, name)]);
- gain_t gain_step = wax::cast<gain_t>(_link[named_prop_t(_gain_props.gain_step_prop, name)]);
+ gain_t gain_min, gain_max, gain_step;
+ boost::tie(gain_min, gain_max, gain_step) = \
+ get_named_prop<gain_range_t>(_props.range, name);
//clip g to be within the allowed range
gain_t g = std::min(std::max(gain_val, gain_min), gain_max);
//set g to be a multiple of the step size
g -= fmod(g, gain_step);
//set g to be the new gain
- _link[named_prop_t(_gain_props.gain_val_prop, name)] = g;
+ _link[named_prop_t(_props.value, name)] = g;
//subtract g out of the total gain left to apply
gain_val -= g;
}