diff options
author | Tom Tsou <tom.tsou@ettus.com> | 2017-07-06 17:25:55 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2017-07-18 12:45:56 -0700 |
commit | f21874e68a413ad8088bef69e3e8c1ef9c352eca (patch) | |
tree | 28c10a22cdbbab036e59b816fff9dc682c767caa /host/utils/converter_benchmark.cpp | |
parent | 5501823223ae7648413d3747badf9553bbd71578 (diff) | |
download | uhd-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/utils/converter_benchmark.cpp')
-rw-r--r-- | host/utils/converter_benchmark.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/host/utils/converter_benchmark.cpp b/host/utils/converter_benchmark.cpp index 0f0c72370..ba521441f 100644 --- a/host/utils/converter_benchmark.cpp +++ b/host/utils/converter_benchmark.cpp @@ -98,6 +98,28 @@ void init_random_vector_complex_int(std::vector<char> &buf_ptr, const size_t n_i } } +struct item32_sc12_3x +{ + uint32_t line0; + uint32_t line1; + uint32_t line2; +}; + +template <typename T> +void init_random_vector_complex_sc12(std::vector<char> &buf_ptr, const size_t n_items) +{ + item32_sc12_3x *const buf = reinterpret_cast<item32_sc12_3x * const>(&buf_ptr[0]); + if (n_items % 4) throw std::invalid_argument(""); + + for (size_t i = 0; i < n_items / 4; i++) { + int16_t iq[8]; + for (auto &k : iq) k = rand() & 0xfff; + buf[i].line0 = iq[0] << 20 | iq[1] << 8 | iq[2] >> 4; + buf[i].line1 = iq[2] << 28 | iq[3] << 16 | iq[4] << 4 | iq[5] >> 8; + buf[i].line2 = iq[5] << 24 | iq[6] << 12 | iq[7] << 0; + } +} + template <typename T> void init_random_vector_real_int(std::vector<char> &buf_ptr, size_t n_items) { @@ -164,6 +186,8 @@ void init_buffers( for (size_t i = 0; i < buf.size(); i++) { if (type == "sc8") { init_random_vector_complex_int<int8_t>(buf[i], n_items); + } else if (type == "sc12") { + init_random_vector_complex_sc12<int16_t>(buf[i], n_items); } else if (type == "sc16") { init_random_vector_complex_int<int16_t>(buf[i], n_items); } else if (type == "sc32") { |