aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/convert/convert_unpack_sc12.cpp
diff options
context:
space:
mode:
authorTom Tsou <tom.tsou@ettus.com>2017-07-06 17:25:55 -0700
committerMartin Braun <martin.braun@ettus.com>2017-07-18 12:45:56 -0700
commitf21874e68a413ad8088bef69e3e8c1ef9c352eca (patch)
tree28c10a22cdbbab036e59b816fff9dc682c767caa /host/lib/convert/convert_unpack_sc12.cpp
parent5501823223ae7648413d3747badf9553bbd71578 (diff)
downloaduhd-f21874e68a413ad8088bef69e3e8c1ef9c352eca.tar.gz
uhd-f21874e68a413ad8088bef69e3e8c1ef9c352eca.tar.bz2
uhd-f21874e68a413ad8088bef69e3e8c1ef9c352eca.zip
convert: Add sc12-sc16 converters
Create missing sc12-sc16 and sc16-sc12 type converters. To avoid replicating the full sc12 converter class object, overload the converter calls with C++11 std::enable_if metafunctions. When used with std::is_floating and std::is_integral templates, this allow a single template interface with compile time function selection and static type checking. Note the below std::enable_if interface is confusing, but quite effective in this case. typename enable_if<is_floating_point<type>::value>::type* = NULL Fixes: #966 Related: #967, #1721
Diffstat (limited to 'host/lib/convert/convert_unpack_sc12.cpp')
-rw-r--r--host/lib/convert/convert_unpack_sc12.cpp50
1 files changed, 46 insertions, 4 deletions
diff --git a/host/lib/convert/convert_unpack_sc12.cpp b/host/lib/convert/convert_unpack_sc12.cpp
index f42e51c00..07f9cffa0 100644
--- a/host/lib/convert/convert_unpack_sc12.cpp
+++ b/host/lib/convert/convert_unpack_sc12.cpp
@@ -20,6 +20,7 @@
#include <uhd/utils/log.hpp>
#include <boost/math/special_functions/round.hpp>
#include <vector>
+#include <type_traits>
using namespace uhd::convert;
@@ -56,7 +57,8 @@ void convert_sc12_item32_3_to_star_4
std::complex<type> &out1,
std::complex<type> &out2,
std::complex<type> &out3,
- const double scalar
+ const double scalar,
+ typename std::enable_if<std::is_floating_point<type>::value>::type* = NULL
)
{
//step 0: extract the lines from the input buffer
@@ -87,6 +89,32 @@ void convert_sc12_item32_3_to_star_4
}
template <typename type, tohost32_type tohost>
+void convert_sc12_item32_3_to_star_4
+(
+ const item32_sc12_3x &input,
+ std::complex<type> &out0,
+ std::complex<type> &out1,
+ std::complex<type> &out2,
+ std::complex<type> &out3,
+ const double,
+ typename std::enable_if<std::is_integral<type>::value>::type* = NULL
+)
+{
+ //step 0: extract the lines from the input buffer
+ const item32_t line0 = tohost(input.line0);
+ const item32_t line1 = tohost(input.line1);
+ const item32_t line2 = tohost(input.line2);
+ const uint64_t line01 = (uint64_t(line0) << 32) | line1;
+ const uint64_t line12 = (uint64_t(line1) << 32) | line2;
+
+ //step 1: extract and load the outputs
+ out0 = std::complex<type>(line0 >> 16 & 0xfff0, line0 >> 4 & 0xfff0);
+ out1 = std::complex<type>(line01 >> 24 & 0xfff0, line1 >> 12 & 0xfff0);
+ out2 = std::complex<type>(line1 >> 0 & 0xfff0, line12 >> 20 & 0xfff0);
+ out3 = std::complex<type>(line2 >> 8 & 0xfff0, line2 << 4 & 0xfff0);
+}
+
+template <typename type, tohost32_type tohost>
struct convert_sc12_item32_1_to_star_1 : public converter
{
convert_sc12_item32_1_to_star_1(void):_scalar(0.0)
@@ -193,18 +221,32 @@ static converter::sptr make_convert_sc12_item32_be_1_to_fc32_1(void)
return converter::sptr(new convert_sc12_item32_1_to_star_1<float, uhd::ntohx>());
}
+static converter::sptr make_convert_sc12_item32_le_1_to_sc16_1(void)
+{
+ return converter::sptr(new convert_sc12_item32_1_to_star_1<short, uhd::wtohx>());
+}
+
+static converter::sptr make_convert_sc12_item32_be_1_to_sc16_1(void)
+{
+ return converter::sptr(new convert_sc12_item32_1_to_star_1<short, uhd::ntohx>());
+}
+
UHD_STATIC_BLOCK(register_convert_unpack_sc12)
{
uhd::convert::register_bytes_per_item("sc12", 3/*bytes*/);
-
uhd::convert::id_type id;
id.num_inputs = 1;
id.num_outputs = 1;
- id.output_format = "fc32";
+ id.output_format = "fc32";
id.input_format = "sc12_item32_le";
uhd::convert::register_converter(id, &make_convert_sc12_item32_le_1_to_fc32_1, PRIORITY_GENERAL);
-
id.input_format = "sc12_item32_be";
uhd::convert::register_converter(id, &make_convert_sc12_item32_be_1_to_fc32_1, PRIORITY_GENERAL);
+
+ id.output_format = "sc16";
+ id.input_format = "sc12_item32_le";
+ uhd::convert::register_converter(id, &make_convert_sc12_item32_le_1_to_sc16_1, PRIORITY_GENERAL);
+ id.input_format = "sc12_item32_be";
+ uhd::convert::register_converter(id, &make_convert_sc12_item32_be_1_to_sc16_1, PRIORITY_GENERAL);
}