From f21874e68a413ad8088bef69e3e8c1ef9c352eca Mon Sep 17 00:00:00 2001 From: Tom Tsou Date: Thu, 6 Jul 2017 17:25:55 -0700 Subject: 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::value>::type* = NULL Fixes: #966 Related: #967, #1721 --- host/tests/convert_test.cpp | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'host/tests') 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 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 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 **********************************************************************/ -- cgit v1.2.3