aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/convert
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib/convert')
-rw-r--r--host/lib/convert/convert_with_tables.cpp77
1 files changed, 25 insertions, 52 deletions
diff --git a/host/lib/convert/convert_with_tables.cpp b/host/lib/convert/convert_with_tables.cpp
index b3702e6ea..00bec95af 100644
--- a/host/lib/convert/convert_with_tables.cpp
+++ b/host/lib/convert/convert_with_tables.cpp
@@ -23,28 +23,19 @@ using namespace uhd::convert;
static const size_t sc16_table_len = size_t(1 << 16);
-#ifdef BOOST_BIG_ENDIAN
-# define ITEM32_BE_TO_R16(x) boost::uint16_t(x >> 16)
-# define ITEM32_BE_TO_I16(x) boost::uint16_t(x)
-# define ITEM32_LE_TO_R16(x) boost::uint16_t(x)
-# define ITEM32_LE_TO_I16(x) boost::uint16_t(x >> 16)
-#else
-# define ITEM32_BE_TO_R16(x) boost::uint16_t(x)
-# define ITEM32_BE_TO_I16(x) boost::uint16_t(x >> 16)
-# define ITEM32_LE_TO_R16(x) boost::uint16_t(x >> 16)
-# define ITEM32_LE_TO_I16(x) boost::uint16_t(x)
-#endif
+typedef boost::uint16_t (*tohost16_type)(boost::uint16_t);
/***********************************************************************
- * Implementation for sc16 be lookup table
+ * Implementation for sc16 lookup table
**********************************************************************/
-template <typename type> class convert_sc16_item32_be_1_to_fcxx_1 : public converter{
+template <typename type, tohost16_type tohost, size_t real_shift, size_t imag_shift>
+class convert_sc16_item32_1_to_fcxx_1 : public converter{
public:
- convert_sc16_item32_be_1_to_fcxx_1(void): _table(sc16_table_len){}
+ convert_sc16_item32_1_to_fcxx_1(void): _table(sc16_table_len){}
void set_scalar(const double scalar){
for (size_t i = 0; i < sc16_table_len; i++){
- const boost::int16_t val = uhd::ntohx(boost::uint16_t(i & 0xffff));
+ const boost::int16_t val = tohost(boost::uint16_t(i & 0xffff));
_table[i] = type(val*scalar);
}
}
@@ -54,10 +45,10 @@ public:
std::complex<type> *output = reinterpret_cast<std::complex<type> *>(outputs[0]);
for (size_t i = 0; i < nsamps; i++){
- const item32_t item_be = input[i];
+ const item32_t item = input[i];
output[i] = std::complex<type>(
- _table[ITEM32_BE_TO_R16(item_be)],
- _table[ITEM32_BE_TO_I16(item_be)]
+ _table[boost::uint16_t(item >> real_shift)],
+ _table[boost::uint16_t(item >> imag_shift)]
);
}
}
@@ -67,53 +58,35 @@ private:
};
/***********************************************************************
- * Implementation for sc16 le lookup table
+ * Factory functions and registration
**********************************************************************/
-template <typename type> class convert_sc16_item32_le_1_to_fcxx_1 : public converter{
-public:
- convert_sc16_item32_le_1_to_fcxx_1(void): _table(sc16_table_len){}
-
- void set_scalar(const double scalar){
- for (size_t i = 0; i < sc16_table_len; i++){
- const boost::int16_t val = uhd::wtohx(boost::uint16_t(i & 0xffff));
- _table[i] = type(val*scalar);
- }
- }
-
- void operator()(const input_type &inputs, const output_type &outputs, const size_t nsamps){
- const item32_t *input = reinterpret_cast<const item32_t *>(inputs[0]);
- std::complex<type> *output = reinterpret_cast<std::complex<type> *>(outputs[0]);
- for (size_t i = 0; i < nsamps; i++){
- const item32_t item_le = input[i];
- output[i] = std::complex<type>(
- _table[ITEM32_LE_TO_R16(item_le)],
- _table[ITEM32_LE_TO_I16(item_le)]
- );
- }
- }
-
-private:
- std::vector<type> _table;
-};
+#ifdef BOOST_BIG_ENDIAN
+# define ITEM32_BE_TO_R16 16
+# define ITEM32_BE_TO_I16 0
+# define ITEM32_LE_TO_R16 0
+# define ITEM32_LE_TO_I16 16
+#else
+# define ITEM32_BE_TO_R16 0
+# define ITEM32_BE_TO_I16 16
+# define ITEM32_LE_TO_R16 16
+# define ITEM32_LE_TO_I16 0
+#endif
-/***********************************************************************
- * Factory functions and registration
- **********************************************************************/
static converter::sptr make_convert_sc16_item32_be_1_to_fc32_1(void){
- return converter::sptr(new convert_sc16_item32_be_1_to_fcxx_1<float>());
+ return converter::sptr(new convert_sc16_item32_1_to_fcxx_1<float, uhd::ntohx, ITEM32_BE_TO_R16, ITEM32_BE_TO_I16>());
}
static converter::sptr make_convert_sc16_item32_be_1_to_fc64_1(void){
- return converter::sptr(new convert_sc16_item32_be_1_to_fcxx_1<double>());
+ return converter::sptr(new convert_sc16_item32_1_to_fcxx_1<double, uhd::ntohx, ITEM32_BE_TO_R16, ITEM32_BE_TO_I16>());
}
static converter::sptr make_convert_sc16_item32_le_1_to_fc32_1(void){
- return converter::sptr(new convert_sc16_item32_le_1_to_fcxx_1<float>());
+ return converter::sptr(new convert_sc16_item32_1_to_fcxx_1<float, uhd::wtohx, ITEM32_LE_TO_R16, ITEM32_LE_TO_I16>());
}
static converter::sptr make_convert_sc16_item32_le_1_to_fc64_1(void){
- return converter::sptr(new convert_sc16_item32_le_1_to_fcxx_1<double>());
+ return converter::sptr(new convert_sc16_item32_1_to_fcxx_1<double, uhd::wtohx, ITEM32_LE_TO_R16, ITEM32_LE_TO_I16>());
}
UHD_STATIC_BLOCK(register_convert_sc16_item32_1_to_fcxx_1){