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/tests | |
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/tests')
-rw-r--r-- | host/tests/convert_test.cpp | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/host/tests/convert_test.cpp b/host/tests/convert_test.cpp index af2828a17..982007d4e 100644 --- a/host/tests/convert_test.cpp +++ b/host/tests/convert_test.cpp @@ -70,13 +70,13 @@ template <typename Range> static void loopback( * Test short conversion **********************************************************************/ static void test_convert_types_sc16( - size_t nsamps, convert::id_type &id, const int extra_div = 1 + size_t nsamps, convert::id_type &id, const int extra_div = 1, int mask = 0xffff ){ //fill the input samples std::vector<sc16_t> input(nsamps), output(nsamps); for(sc16_t &in: input) in = sc16_t( - short((float((std::rand())/(double(RAND_MAX)/2)) - 1)*32767/extra_div), - short((float((std::rand())/(double(RAND_MAX)/2)) - 1)*32767/extra_div) + short((float((std::rand())/(double(RAND_MAX)/2)) - 1)*32767/extra_div) & mask, + short((float((std::rand())/(double(RAND_MAX)/2)) - 1)*32767/extra_div) & mask ); //run the loopback and test @@ -235,6 +235,31 @@ BOOST_AUTO_TEST_CASE(test_convert_types_be_sc12_with_fc32){ } } +BOOST_AUTO_TEST_CASE(test_convert_types_le_sc16_and_sc12){ + convert::id_type id; + id.input_format = "sc16"; + id.num_inputs = 1; + id.num_outputs = 1; + + //try various lengths to test edge cases + id.output_format = "sc12_item32_le"; + for (size_t nsamps = 1; nsamps < 16; nsamps++){ + test_convert_types_sc16(nsamps, id, 1, 0xfff0); + } +} + +BOOST_AUTO_TEST_CASE(test_convert_types_be_sc16_and_sc12){ + convert::id_type id; + id.input_format = "sc16"; + id.num_inputs = 1; + id.num_outputs = 1; + + id.output_format = "sc12_item32_be"; + for (size_t nsamps = 1; nsamps < 16; nsamps++){ + test_convert_types_sc16(nsamps, id, 1, 0xfff0); + } +} + /*********************************************************************** * Test float to/from fc32 conversion loopback **********************************************************************/ |