diff options
author | Josh Blum <josh@joshknows.com> | 2011-11-12 15:45:52 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2011-11-12 15:45:52 -0800 |
commit | dd782308940e4b206e798eb2f0fa203b6e8c7f07 (patch) | |
tree | 9111a6128a4351ca7d9773e5ee4d057871ffd7b7 /host/lib/convert | |
parent | 74106084ed94668f11777f856e9b42e80b5d6599 (diff) | |
download | uhd-dd782308940e4b206e798eb2f0fa203b6e8c7f07.tar.gz uhd-dd782308940e4b206e798eb2f0fa203b6e8c7f07.tar.bz2 uhd-dd782308940e4b206e798eb2f0fa203b6e8c7f07.zip |
convert: made conversion functions into classes so they can keep state
Diffstat (limited to 'host/lib/convert')
-rw-r--r-- | host/lib/convert/convert_common.hpp | 26 | ||||
-rw-r--r-- | host/lib/convert/convert_impl.cpp | 4 | ||||
-rw-r--r-- | host/lib/convert/gen_convert_general.py | 10 |
3 files changed, 15 insertions, 25 deletions
diff --git a/host/lib/convert/convert_common.hpp b/host/lib/convert/convert_common.hpp index 34fb848c3..ce82f6216 100644 --- a/host/lib/convert/convert_common.hpp +++ b/host/lib/convert/convert_common.hpp @@ -21,30 +21,30 @@ #include <uhd/convert.hpp> #include <uhd/utils/static.hpp> #include <boost/cstdint.hpp> +#include <boost/bind.hpp> #include <complex> -#define _DECLARE_CONVERTER(fcn, in_form, num_in, out_form, num_out, prio) \ - static void fcn( \ - const uhd::convert::input_type &inputs, \ - const uhd::convert::output_type &outputs, \ - const size_t nsamps, const double scale_factor \ - ); \ - UHD_STATIC_BLOCK(__register_##fcn##_##prio){ \ +#define _DECLARE_CONVERTER(name, in_form, num_in, out_form, num_out, prio) \ + struct name : public uhd::convert::converter{ \ + static sptr make(void){return sptr(new name());} \ + double scale_factor; \ + void set_scalar(const double s){scale_factor = s;} \ + void operator()(const input_type&, const output_type&, const size_t); \ + }; \ + UHD_STATIC_BLOCK(__register_##name##_##prio){ \ uhd::convert::id_type id; \ id.input_format = #in_form; \ id.num_inputs = num_in; \ id.output_format = #out_form; \ id.num_outputs = num_out; \ - uhd::convert::register_converter(id, fcn, prio); \ + uhd::convert::register_converter(id, boost::bind(&name::make), prio); \ } \ - static void fcn( \ - const uhd::convert::input_type &inputs, \ - const uhd::convert::output_type &outputs, \ - const size_t nsamps, const double scale_factor \ + void name::operator()( \ + const input_type &inputs, const output_type &outputs, const size_t nsamps \ ) #define DECLARE_CONVERTER(in_form, num_in, out_form, num_out, prio) \ - _DECLARE_CONVERTER(__convert_##in_form##_##num_in##_##out_form##_##num_out, in_form, num_in, out_form, num_out, prio) + _DECLARE_CONVERTER(__convert_##in_form##_##num_in##_##out_form##_##num_out##_##prio, in_form, num_in, out_form, num_out, prio) /*********************************************************************** * Typedefs diff --git a/host/lib/convert/convert_impl.cpp b/host/lib/convert/convert_impl.cpp index f05be6ada..12ad54486 100644 --- a/host/lib/convert/convert_impl.cpp +++ b/host/lib/convert/convert_impl.cpp @@ -69,8 +69,8 @@ UHD_SINGLETON_FCN(fcn_table_type, get_table); **********************************************************************/ void uhd::convert::register_converter( const id_type &id, - function_type fcn, - priority_type prio + const function_type &fcn, + const priority_type prio ){ //get a reference to the function table fcn_table_type &table = get_table(); diff --git a/host/lib/convert/gen_convert_general.py b/host/lib/convert/gen_convert_general.py index 52b4212b4..a1bc7aaaf 100644 --- a/host/lib/convert/gen_convert_general.py +++ b/host/lib/convert/gen_convert_general.py @@ -33,8 +33,6 @@ DECLARE_CONVERTER(item32, 1, sc16_item32_$(end), 1, PRIORITY_GENERAL){ const item32_t *input = reinterpret_cast<const item32_t *>(inputs[0]); item32_t *output = reinterpret_cast<item32_t *>(outputs[0]); - if (scale_factor == 0){} //avoids unused warning - for (size_t i = 0; i < nsamps; i++){ output[i] = $(to_wire)(input[i]); } @@ -44,8 +42,6 @@ DECLARE_CONVERTER(sc16_item32_$(end), 1, item32, 1, PRIORITY_GENERAL){ const item32_t *input = reinterpret_cast<const item32_t *>(inputs[0]); item32_t *output = reinterpret_cast<item32_t *>(outputs[0]); - if (scale_factor == 0){} //avoids unused warning - for (size_t i = 0; i < nsamps; i++){ output[i] = $(to_host)(input[i]); } @@ -103,8 +99,6 @@ DECLARE_CONVERTER($(cpu_type), $(width), sc16_item16_usrp1, 1, PRIORITY_GENERAL) #end for boost::uint16_t *output = reinterpret_cast<boost::uint16_t *>(outputs[0]); - if (scale_factor == 0){} //avoids unused warning - for (size_t i = 0, j = 0; i < nsamps; i++){ #for $w in range($width) output[j++] = $(to_wire)(boost::int16_t(input$(w)[i].real()$(do_scale))); @@ -119,8 +113,6 @@ DECLARE_CONVERTER(sc16_item16_usrp1, 1, $(cpu_type), $(width), PRIORITY_GENERAL) $(cpu_type)_t *output$(w) = reinterpret_cast<$(cpu_type)_t *>(outputs[$(w)]); #end for - if (scale_factor == 0){} //avoids unused warning - for (size_t i = 0, j = 0; i < nsamps; i++){ #for $w in range($width) output$(w)[i] = $(cpu_type)_t( @@ -138,8 +130,6 @@ DECLARE_CONVERTER(sc8_item16_usrp1, 1, $(cpu_type), $(width), PRIORITY_GENERAL){ $(cpu_type)_t *output$(w) = reinterpret_cast<$(cpu_type)_t *>(outputs[$(w)]); #end for - if (scale_factor == 0){} //avoids unused warning - for (size_t i = 0, j = 0; i < nsamps; i++){ #for $w in range($width) { |