2010-06-08 07:00:54 +00:00
|
|
|
//
|
2012-02-07 19:59:42 +00:00
|
|
|
// Copyright 2011-2012 Ettus Research LLC
|
2018-02-19 23:30:32 +00:00
|
|
|
// Copyright 2018 Ettus Research, a National Instruments Company
|
2010-06-08 07:00:54 +00:00
|
|
|
//
|
2018-02-19 23:30:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2010-06-08 07:00:54 +00:00
|
|
|
//
|
|
|
|
|
|
2011-01-05 03:29:39 +00:00
|
|
|
#include <uhd/convert.hpp>
|
2016-10-31 21:30:52 +00:00
|
|
|
#include <stdint.h>
|
2019-01-14 18:35:25 +00:00
|
|
|
#include <boost/test/unit_test.hpp>
|
2010-06-08 07:00:54 +00:00
|
|
|
#include <complex>
|
2010-08-25 00:26:07 +00:00
|
|
|
#include <cstdlib>
|
2011-01-05 03:29:39 +00:00
|
|
|
#include <iostream>
|
2019-01-14 18:35:25 +00:00
|
|
|
#include <vector>
|
2010-06-08 07:00:54 +00:00
|
|
|
|
|
|
|
|
using namespace uhd;
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// typedefs for complex types
|
2016-10-31 21:30:52 +00:00
|
|
|
typedef std::complex<int16_t> sc16_t;
|
2010-08-25 00:26:07 +00:00
|
|
|
typedef std::complex<float> fc32_t;
|
2011-02-04 00:45:34 +00:00
|
|
|
typedef std::complex<double> fc64_t;
|
2010-08-25 00:26:07 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
#define MY_CHECK_CLOSE(a, b, f) \
|
|
|
|
|
{ \
|
|
|
|
|
BOOST_CHECK_MESSAGE(std::abs((a) - (b)) < f, \
|
|
|
|
|
"\n\t" << #a << " (" << (a) << ") error " << #b << " (" << (b) << ")"); \
|
|
|
|
|
}
|
2010-11-17 17:54:56 +00:00
|
|
|
|
2010-08-25 00:26:07 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* Loopback runner:
|
|
|
|
|
* convert input buffer into intermediate buffer
|
|
|
|
|
* convert intermediate buffer into output buffer
|
|
|
|
|
**********************************************************************/
|
2019-01-14 18:35:25 +00:00
|
|
|
template <typename Range>
|
|
|
|
|
static void loopback(size_t nsamps,
|
|
|
|
|
convert::id_type& in_id,
|
|
|
|
|
convert::id_type& out_id,
|
|
|
|
|
const Range& input,
|
|
|
|
|
Range& output,
|
|
|
|
|
const int prio_in = -1,
|
|
|
|
|
const int prio_out = -1)
|
|
|
|
|
{
|
|
|
|
|
// make this buffer large enough for all test types
|
2016-10-31 21:30:52 +00:00
|
|
|
std::vector<uint64_t> interm(nsamps);
|
2010-06-08 07:00:54 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
std::vector<const void*> input0(1, &input[0]), input1(1, &interm[0]);
|
|
|
|
|
std::vector<void*> output0(1, &interm[0]), output1(1, &output[0]);
|
2011-01-05 03:29:39 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// convert to intermediate type
|
2012-04-27 23:19:49 +00:00
|
|
|
convert::converter::sptr c0 = convert::get_converter(in_id, prio_in)();
|
2011-11-12 23:45:52 +00:00
|
|
|
c0->set_scalar(32767.);
|
|
|
|
|
c0->conv(input0, output0, nsamps);
|
2010-06-08 07:00:54 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// convert back to host type
|
2012-04-27 23:19:49 +00:00
|
|
|
convert::converter::sptr c1 = convert::get_converter(out_id, prio_out)();
|
2019-01-14 18:35:25 +00:00
|
|
|
c1->set_scalar(1 / 32767.);
|
2011-11-12 23:45:52 +00:00
|
|
|
c1->conv(input1, output1, nsamps);
|
2010-06-08 07:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
2010-08-25 00:26:07 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* Test short conversion
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
static void test_convert_types_sc16(
|
2019-01-14 18:35:25 +00:00
|
|
|
size_t nsamps, convert::id_type& id, const int extra_div = 1, int mask = 0xffff)
|
|
|
|
|
{
|
|
|
|
|
// fill the input samples
|
2010-08-25 00:26:07 +00:00
|
|
|
std::vector<sc16_t> input(nsamps), output(nsamps);
|
2019-01-14 18:35:25 +00:00
|
|
|
for (sc16_t& in : input)
|
|
|
|
|
in = sc16_t(
|
|
|
|
|
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
|
|
|
|
|
convert::id_type in_id = id;
|
2011-10-04 00:07:45 +00:00
|
|
|
convert::id_type out_id = id;
|
2011-10-12 07:39:04 +00:00
|
|
|
std::swap(out_id.input_format, out_id.output_format);
|
2011-10-04 00:07:45 +00:00
|
|
|
std::swap(out_id.num_inputs, out_id.num_outputs);
|
|
|
|
|
loopback(nsamps, in_id, out_id, input, output);
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_CHECK_EQUAL_COLLECTIONS(
|
|
|
|
|
input.begin(), input.end(), output.begin(), output.end());
|
2010-08-25 00:26:07 +00:00
|
|
|
}
|
2010-06-08 07:00:54 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_be_sc16)
|
|
|
|
|
{
|
2011-10-04 00:07:45 +00:00
|
|
|
convert::id_type id;
|
2019-01-14 18:35:25 +00:00
|
|
|
id.input_format = "sc16";
|
|
|
|
|
id.num_inputs = 1;
|
2011-10-12 07:39:04 +00:00
|
|
|
id.output_format = "sc16_item32_be";
|
2019-01-14 18:35:25 +00:00
|
|
|
id.num_outputs = 1;
|
2010-06-08 07:00:54 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
|
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
2011-10-04 00:07:45 +00:00
|
|
|
test_convert_types_sc16(nsamps, id);
|
2010-08-25 00:26:07 +00:00
|
|
|
}
|
2010-06-08 07:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_le_sc16)
|
|
|
|
|
{
|
2011-10-04 00:07:45 +00:00
|
|
|
convert::id_type id;
|
2019-01-14 18:35:25 +00:00
|
|
|
id.input_format = "sc16";
|
|
|
|
|
id.num_inputs = 1;
|
2011-10-12 07:39:04 +00:00
|
|
|
id.output_format = "sc16_item32_le";
|
2019-01-14 18:35:25 +00:00
|
|
|
id.num_outputs = 1;
|
2010-06-08 07:00:54 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
|
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
2011-10-04 00:07:45 +00:00
|
|
|
test_convert_types_sc16(nsamps, id);
|
2010-08-25 00:26:07 +00:00
|
|
|
}
|
2010-06-08 07:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
2019-07-18 21:36:14 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_chdr_sc16)
|
|
|
|
|
{
|
|
|
|
|
convert::id_type id;
|
|
|
|
|
id.input_format = "sc16";
|
|
|
|
|
id.num_inputs = 1;
|
|
|
|
|
id.output_format = "sc16_chdr";
|
|
|
|
|
id.num_outputs = 1;
|
|
|
|
|
|
|
|
|
|
// try various lengths to test edge cases
|
|
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
|
|
|
|
test_convert_types_sc16(nsamps, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-25 00:26:07 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* Test float conversion
|
|
|
|
|
**********************************************************************/
|
2011-02-04 00:45:34 +00:00
|
|
|
template <typename data_type>
|
|
|
|
|
static void test_convert_types_for_floats(
|
2019-01-14 18:35:25 +00:00
|
|
|
size_t nsamps, convert::id_type& id, const double extra_scale = 1.0)
|
|
|
|
|
{
|
2011-02-04 00:45:34 +00:00
|
|
|
typedef typename data_type::value_type value_type;
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// fill the input samples
|
2011-02-04 00:45:34 +00:00
|
|
|
std::vector<data_type> input(nsamps), output(nsamps);
|
2019-01-14 18:35:25 +00:00
|
|
|
for (data_type& in : input)
|
|
|
|
|
in = data_type(
|
|
|
|
|
((std::rand() / (value_type(RAND_MAX) / 2)) - 1) * float(extra_scale),
|
|
|
|
|
((std::rand() / (value_type(RAND_MAX) / 2)) - 1) * float(extra_scale));
|
2010-06-08 07:00:54 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// run the loopback and test
|
|
|
|
|
convert::id_type in_id = id;
|
2011-10-04 00:07:45 +00:00
|
|
|
convert::id_type out_id = id;
|
2011-10-12 07:39:04 +00:00
|
|
|
std::swap(out_id.input_format, out_id.output_format);
|
2011-10-04 00:07:45 +00:00
|
|
|
std::swap(out_id.num_inputs, out_id.num_outputs);
|
2012-04-27 23:19:49 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// make a list of all prio: best/generic combos
|
2012-04-27 23:19:49 +00:00
|
|
|
typedef std::pair<int, int> int_pair_t;
|
2018-04-26 20:13:32 +00:00
|
|
|
const std::vector<int_pair_t> prios{
|
2019-01-14 18:35:25 +00:00
|
|
|
int_pair_t(0, 0), int_pair_t(-1, 0), int_pair_t(0, -1), int_pair_t(-1, -1)};
|
|
|
|
|
|
|
|
|
|
// loopback foreach prio combo (generic vs best)
|
|
|
|
|
for (const auto& prio : prios) {
|
2012-04-27 23:19:49 +00:00
|
|
|
loopback(nsamps, in_id, out_id, input, output, prio.first, prio.second);
|
2019-01-14 18:35:25 +00:00
|
|
|
for (size_t i = 0; i < nsamps; i++) {
|
|
|
|
|
MY_CHECK_CLOSE(input[i].real(), output[i].real(), value_type(1. / (1 << 14)));
|
|
|
|
|
MY_CHECK_CLOSE(input[i].imag(), output[i].imag(), value_type(1. / (1 << 14)));
|
2012-04-27 23:19:49 +00:00
|
|
|
}
|
2010-08-25 00:26:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-06-08 21:55:57 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_be_fc32)
|
|
|
|
|
{
|
2011-10-04 00:07:45 +00:00
|
|
|
convert::id_type id;
|
2019-01-14 18:35:25 +00:00
|
|
|
id.input_format = "fc32";
|
|
|
|
|
id.num_inputs = 1;
|
2011-10-12 07:39:04 +00:00
|
|
|
id.output_format = "sc16_item32_be";
|
2019-01-14 18:35:25 +00:00
|
|
|
id.num_outputs = 1;
|
2010-06-08 07:00:54 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
|
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
2011-10-04 00:07:45 +00:00
|
|
|
test_convert_types_for_floats<fc32_t>(nsamps, id);
|
2010-08-25 00:26:07 +00:00
|
|
|
}
|
2010-06-08 07:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_le_fc32)
|
|
|
|
|
{
|
2011-10-04 00:07:45 +00:00
|
|
|
convert::id_type id;
|
2019-01-14 18:35:25 +00:00
|
|
|
id.input_format = "fc32";
|
|
|
|
|
id.num_inputs = 1;
|
2011-10-12 07:39:04 +00:00
|
|
|
id.output_format = "sc16_item32_le";
|
2019-01-14 18:35:25 +00:00
|
|
|
id.num_outputs = 1;
|
2010-06-08 07:00:54 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
|
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
2011-10-04 00:07:45 +00:00
|
|
|
test_convert_types_for_floats<fc32_t>(nsamps, id);
|
2011-02-04 00:45:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-18 21:36:14 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_chdr_fc32)
|
|
|
|
|
{
|
|
|
|
|
convert::id_type id;
|
|
|
|
|
id.input_format = "fc32";
|
|
|
|
|
id.num_inputs = 1;
|
|
|
|
|
id.output_format = "sc16_chdr";
|
|
|
|
|
id.num_outputs = 1;
|
|
|
|
|
|
|
|
|
|
// try various lengths to test edge cases
|
|
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
|
|
|
|
test_convert_types_for_floats<fc32_t>(nsamps, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_be_fc64)
|
|
|
|
|
{
|
2011-10-04 00:07:45 +00:00
|
|
|
convert::id_type id;
|
2019-01-14 18:35:25 +00:00
|
|
|
id.input_format = "fc64";
|
|
|
|
|
id.num_inputs = 1;
|
2011-10-12 07:39:04 +00:00
|
|
|
id.output_format = "sc16_item32_be";
|
2019-01-14 18:35:25 +00:00
|
|
|
id.num_outputs = 1;
|
2011-02-04 00:45:34 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
|
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
2011-10-04 00:07:45 +00:00
|
|
|
test_convert_types_for_floats<fc64_t>(nsamps, id);
|
2011-02-04 00:45:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_le_fc64)
|
|
|
|
|
{
|
2011-10-04 00:07:45 +00:00
|
|
|
convert::id_type id;
|
2019-01-14 18:35:25 +00:00
|
|
|
id.input_format = "fc64";
|
|
|
|
|
id.num_inputs = 1;
|
2011-10-12 07:39:04 +00:00
|
|
|
id.output_format = "sc16_item32_le";
|
2019-01-14 18:35:25 +00:00
|
|
|
id.num_outputs = 1;
|
2011-02-04 00:45:34 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
|
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
2011-10-04 00:07:45 +00:00
|
|
|
test_convert_types_for_floats<fc64_t>(nsamps, id);
|
2010-08-25 00:26:07 +00:00
|
|
|
}
|
2010-06-08 07:00:54 +00:00
|
|
|
}
|
2010-08-30 19:33:13 +00:00
|
|
|
|
2019-07-18 21:36:14 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_chdr_fc64)
|
|
|
|
|
{
|
|
|
|
|
convert::id_type id;
|
|
|
|
|
id.input_format = "fc64";
|
|
|
|
|
id.num_inputs = 1;
|
|
|
|
|
id.output_format = "sc16_chdr";
|
|
|
|
|
id.num_outputs = 1;
|
|
|
|
|
|
|
|
|
|
// try various lengths to test edge cases
|
|
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
|
|
|
|
test_convert_types_for_floats<fc64_t>(nsamps, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-04 19:04:07 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* Test float to/from sc12 conversion loopback
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_le_sc12_with_fc32)
|
|
|
|
|
{
|
2014-02-04 19:04:07 +00:00
|
|
|
convert::id_type id;
|
2019-01-14 18:35:25 +00:00
|
|
|
id.input_format = "fc32";
|
|
|
|
|
id.num_inputs = 1;
|
2014-02-04 19:04:07 +00:00
|
|
|
id.output_format = "sc12_item32_le";
|
2019-01-14 18:35:25 +00:00
|
|
|
id.num_outputs = 1;
|
2014-02-04 19:04:07 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
|
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
|
|
|
|
test_convert_types_for_floats<fc32_t>(nsamps, id, 1. / 16);
|
2014-02-04 19:04:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_be_sc12_with_fc32)
|
|
|
|
|
{
|
2014-02-04 19:04:07 +00:00
|
|
|
convert::id_type id;
|
2019-01-14 18:35:25 +00:00
|
|
|
id.input_format = "fc32";
|
|
|
|
|
id.num_inputs = 1;
|
2014-02-04 19:04:07 +00:00
|
|
|
id.output_format = "sc12_item32_be";
|
2019-01-14 18:35:25 +00:00
|
|
|
id.num_outputs = 1;
|
2014-02-04 19:04:07 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
|
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
|
|
|
|
test_convert_types_for_floats<fc32_t>(nsamps, id, 1. / 16);
|
2014-02-04 19:04:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_le_sc16_and_sc12)
|
|
|
|
|
{
|
2017-07-07 00:25:55 +00:00
|
|
|
convert::id_type id;
|
|
|
|
|
id.input_format = "sc16";
|
2019-01-14 18:35:25 +00:00
|
|
|
id.num_inputs = 1;
|
|
|
|
|
id.num_outputs = 1;
|
2017-07-07 00:25:55 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
2017-07-07 00:25:55 +00:00
|
|
|
id.output_format = "sc12_item32_le";
|
2019-01-14 18:35:25 +00:00
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
2017-07-07 00:25:55 +00:00
|
|
|
test_convert_types_sc16(nsamps, id, 1, 0xfff0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_be_sc16_and_sc12)
|
|
|
|
|
{
|
2017-07-07 00:25:55 +00:00
|
|
|
convert::id_type id;
|
|
|
|
|
id.input_format = "sc16";
|
2019-01-14 18:35:25 +00:00
|
|
|
id.num_inputs = 1;
|
|
|
|
|
id.num_outputs = 1;
|
2017-07-07 00:25:55 +00:00
|
|
|
|
|
|
|
|
id.output_format = "sc12_item32_be";
|
2019-01-14 18:35:25 +00:00
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
2017-07-07 00:25:55 +00:00
|
|
|
test_convert_types_sc16(nsamps, id, 1, 0xfff0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-04 19:04:07 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* Test float to/from fc32 conversion loopback
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_le_fc32_with_fc32)
|
|
|
|
|
{
|
2014-02-04 19:04:07 +00:00
|
|
|
convert::id_type id;
|
2019-01-14 18:35:25 +00:00
|
|
|
id.input_format = "fc32";
|
|
|
|
|
id.num_inputs = 1;
|
2014-02-04 19:04:07 +00:00
|
|
|
id.output_format = "fc32_item32_le";
|
2019-01-14 18:35:25 +00:00
|
|
|
id.num_outputs = 1;
|
2014-02-04 19:04:07 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
|
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
2014-02-04 19:04:07 +00:00
|
|
|
test_convert_types_for_floats<fc32_t>(nsamps, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_be_fc32_with_fc32)
|
|
|
|
|
{
|
2014-02-04 19:04:07 +00:00
|
|
|
convert::id_type id;
|
2019-01-14 18:35:25 +00:00
|
|
|
id.input_format = "fc32";
|
|
|
|
|
id.num_inputs = 1;
|
2014-02-04 19:04:07 +00:00
|
|
|
id.output_format = "fc32_item32_be";
|
2019-01-14 18:35:25 +00:00
|
|
|
id.num_outputs = 1;
|
2014-02-04 19:04:07 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
|
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
2014-02-04 19:04:07 +00:00
|
|
|
test_convert_types_for_floats<fc32_t>(nsamps, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-18 21:36:14 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_fc32_with_fc32_chdr)
|
|
|
|
|
{
|
|
|
|
|
convert::id_type id;
|
|
|
|
|
id.input_format = "fc32";
|
|
|
|
|
id.num_inputs = 1;
|
|
|
|
|
id.output_format = "fc32_chdr";
|
|
|
|
|
id.num_outputs = 1;
|
|
|
|
|
|
|
|
|
|
// try various lengths to test edge cases
|
|
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
|
|
|
|
test_convert_types_for_floats<fc32_t>(nsamps, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-30 19:33:13 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* Test float to short conversion loopback
|
|
|
|
|
**********************************************************************/
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_fc32_to_sc16)
|
|
|
|
|
{
|
2011-10-04 00:07:45 +00:00
|
|
|
convert::id_type in_id;
|
2019-01-14 18:35:25 +00:00
|
|
|
in_id.input_format = "fc32";
|
|
|
|
|
in_id.num_inputs = 1;
|
2011-10-12 07:39:04 +00:00
|
|
|
in_id.output_format = "sc16_item32_le";
|
2019-01-14 18:35:25 +00:00
|
|
|
in_id.num_outputs = 1;
|
2011-10-04 00:07:45 +00:00
|
|
|
|
|
|
|
|
convert::id_type out_id;
|
2019-01-14 18:35:25 +00:00
|
|
|
out_id.input_format = "sc16_item32_le";
|
|
|
|
|
out_id.num_inputs = 1;
|
2011-10-12 07:39:04 +00:00
|
|
|
out_id.output_format = "sc16";
|
2019-01-14 18:35:25 +00:00
|
|
|
out_id.num_outputs = 1;
|
2010-08-30 19:33:13 +00:00
|
|
|
|
|
|
|
|
const size_t nsamps = 13;
|
|
|
|
|
std::vector<fc32_t> input(nsamps);
|
2019-01-14 18:35:25 +00:00
|
|
|
for (fc32_t& in : input)
|
|
|
|
|
in = fc32_t(
|
|
|
|
|
(std::rand() / (RAND_MAX / 2.0)) - 1, (std::rand() / (RAND_MAX / 2.0)) - 1);
|
2016-10-31 21:30:52 +00:00
|
|
|
std::vector<uint32_t> interm(nsamps);
|
2011-01-05 03:29:39 +00:00
|
|
|
std::vector<sc16_t> output(nsamps);
|
2010-08-30 19:33:13 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
std::vector<const void*> input0(1, &input[0]), input1(1, &interm[0]);
|
|
|
|
|
std::vector<void*> output0(1, &interm[0]), output1(1, &output[0]);
|
2011-01-05 03:29:39 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// convert float to intermediate
|
2011-11-12 23:45:52 +00:00
|
|
|
convert::converter::sptr c0 = convert::get_converter(in_id)();
|
|
|
|
|
c0->set_scalar(32767.);
|
|
|
|
|
c0->conv(input0, output0, nsamps);
|
2010-08-30 19:33:13 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// convert intermediate to short
|
2011-11-12 23:45:52 +00:00
|
|
|
convert::converter::sptr c1 = convert::get_converter(out_id)();
|
2019-01-14 18:35:25 +00:00
|
|
|
c1->set_scalar(1 / 32767.);
|
2011-11-12 23:45:52 +00:00
|
|
|
c1->conv(input1, output1, nsamps);
|
2010-08-30 19:33:13 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// test that the inputs and outputs match
|
|
|
|
|
for (size_t i = 0; i < nsamps; i++) {
|
|
|
|
|
MY_CHECK_CLOSE(input[i].real(), output[i].real() / float(32767), float(0.01));
|
|
|
|
|
MY_CHECK_CLOSE(input[i].imag(), output[i].imag() / float(32767), float(0.01));
|
2010-08-30 19:33:13 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* Test short to float conversion loopback
|
|
|
|
|
**********************************************************************/
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_sc16_to_fc32)
|
|
|
|
|
{
|
2011-10-04 00:07:45 +00:00
|
|
|
convert::id_type in_id;
|
2019-01-14 18:35:25 +00:00
|
|
|
in_id.input_format = "sc16";
|
|
|
|
|
in_id.num_inputs = 1;
|
2011-10-12 07:39:04 +00:00
|
|
|
in_id.output_format = "sc16_item32_le";
|
2019-01-14 18:35:25 +00:00
|
|
|
in_id.num_outputs = 1;
|
2011-10-04 00:07:45 +00:00
|
|
|
|
|
|
|
|
convert::id_type out_id;
|
2019-01-14 18:35:25 +00:00
|
|
|
out_id.input_format = "sc16_item32_le";
|
|
|
|
|
out_id.num_inputs = 1;
|
2011-10-12 07:39:04 +00:00
|
|
|
out_id.output_format = "fc32";
|
2019-01-14 18:35:25 +00:00
|
|
|
out_id.num_outputs = 1;
|
2010-08-30 19:33:13 +00:00
|
|
|
|
|
|
|
|
const size_t nsamps = 13;
|
|
|
|
|
std::vector<sc16_t> input(nsamps);
|
2019-01-14 18:35:25 +00:00
|
|
|
for (sc16_t& in : input)
|
|
|
|
|
in = sc16_t(std::rand() - (RAND_MAX / 2), std::rand() - (RAND_MAX / 2));
|
2016-10-31 21:30:52 +00:00
|
|
|
std::vector<uint32_t> interm(nsamps);
|
2011-01-05 03:29:39 +00:00
|
|
|
std::vector<fc32_t> output(nsamps);
|
2010-08-30 19:33:13 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
std::vector<const void*> input0(1, &input[0]), input1(1, &interm[0]);
|
|
|
|
|
std::vector<void*> output0(1, &interm[0]), output1(1, &output[0]);
|
2011-01-05 03:29:39 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// convert short to intermediate
|
2011-11-12 23:45:52 +00:00
|
|
|
convert::converter::sptr c0 = convert::get_converter(in_id)();
|
|
|
|
|
c0->set_scalar(32767.);
|
|
|
|
|
c0->conv(input0, output0, nsamps);
|
2010-08-30 19:33:13 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// convert intermediate to float
|
2011-11-12 23:45:52 +00:00
|
|
|
convert::converter::sptr c1 = convert::get_converter(out_id)();
|
2019-01-14 18:35:25 +00:00
|
|
|
c1->set_scalar(1 / 32767.);
|
2011-11-12 23:45:52 +00:00
|
|
|
c1->conv(input1, output1, nsamps);
|
2010-08-30 19:33:13 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// test that the inputs and outputs match
|
|
|
|
|
for (size_t i = 0; i < nsamps; i++) {
|
|
|
|
|
MY_CHECK_CLOSE(input[i].real() / float(32767), output[i].real(), float(0.01));
|
|
|
|
|
MY_CHECK_CLOSE(input[i].imag() / float(32767), output[i].imag(), float(0.01));
|
2010-08-30 19:33:13 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-02-07 19:59:42 +00:00
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* Test sc8 conversions
|
|
|
|
|
**********************************************************************/
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_fc64_and_sc8)
|
|
|
|
|
{
|
2012-02-07 19:59:42 +00:00
|
|
|
convert::id_type id;
|
|
|
|
|
id.input_format = "fc64";
|
2019-01-14 18:35:25 +00:00
|
|
|
id.num_inputs = 1;
|
|
|
|
|
id.num_outputs = 1;
|
2012-02-07 19:59:42 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
2012-02-07 19:59:42 +00:00
|
|
|
id.output_format = "sc8_item32_le";
|
2019-01-14 18:35:25 +00:00
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
|
|
|
|
test_convert_types_for_floats<fc64_t>(nsamps, id, 1. / 256);
|
2012-02-07 19:59:42 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
2012-02-07 19:59:42 +00:00
|
|
|
id.output_format = "sc8_item32_be";
|
2019-01-14 18:35:25 +00:00
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
|
|
|
|
test_convert_types_for_floats<fc64_t>(nsamps, id, 1. / 256);
|
2012-02-07 19:59:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_fc32_and_sc8)
|
|
|
|
|
{
|
2012-02-07 19:59:42 +00:00
|
|
|
convert::id_type id;
|
|
|
|
|
id.input_format = "fc32";
|
2019-01-14 18:35:25 +00:00
|
|
|
id.num_inputs = 1;
|
|
|
|
|
id.num_outputs = 1;
|
2012-02-07 19:59:42 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
2012-02-07 19:59:42 +00:00
|
|
|
id.output_format = "sc8_item32_le";
|
2019-01-14 18:35:25 +00:00
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
|
|
|
|
test_convert_types_for_floats<fc32_t>(nsamps, id, 1. / 256);
|
2012-02-07 19:59:42 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
2012-02-07 19:59:42 +00:00
|
|
|
id.output_format = "sc8_item32_be";
|
2019-01-14 18:35:25 +00:00
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
|
|
|
|
test_convert_types_for_floats<fc32_t>(nsamps, id, 1. / 256);
|
2012-02-07 19:59:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_sc16_and_sc8)
|
|
|
|
|
{
|
2012-02-07 19:59:42 +00:00
|
|
|
convert::id_type id;
|
|
|
|
|
id.input_format = "sc16";
|
2019-01-14 18:35:25 +00:00
|
|
|
id.num_inputs = 1;
|
|
|
|
|
id.num_outputs = 1;
|
2012-02-07 19:59:42 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
2012-02-07 19:59:42 +00:00
|
|
|
id.output_format = "sc8_item32_le";
|
2019-01-14 18:35:25 +00:00
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
2012-02-07 19:59:42 +00:00
|
|
|
test_convert_types_sc16(nsamps, id, 256);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
2012-02-07 19:59:42 +00:00
|
|
|
id.output_format = "sc8_item32_be";
|
2019-01-14 18:35:25 +00:00
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
2012-02-07 19:59:42 +00:00
|
|
|
test_convert_types_sc16(nsamps, id, 256);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-15 15:23:12 +00:00
|
|
|
|
|
|
|
|
/***********************************************************************
|
2015-09-01 23:00:31 +00:00
|
|
|
* Test u8 conversion
|
2015-01-15 15:23:12 +00:00
|
|
|
**********************************************************************/
|
2019-01-14 18:35:25 +00:00
|
|
|
static void test_convert_types_u8(size_t nsamps, convert::id_type& id)
|
|
|
|
|
{
|
|
|
|
|
// fill the input samples
|
2016-10-31 21:30:52 +00:00
|
|
|
std::vector<uint8_t> input(nsamps), output(nsamps);
|
2019-01-14 18:35:25 +00:00
|
|
|
for (uint8_t& in : input)
|
|
|
|
|
in = uint8_t(std::rand() & 0xFF);
|
|
|
|
|
// uint32_t d = 48;
|
|
|
|
|
// for(uint8_t &in: input) in = d++;
|
2015-01-15 15:23:12 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// run the loopback and test
|
|
|
|
|
convert::id_type in_id = id;
|
2015-01-15 15:23:12 +00:00
|
|
|
convert::id_type out_id = id;
|
|
|
|
|
std::swap(out_id.input_format, out_id.output_format);
|
|
|
|
|
std::swap(out_id.num_inputs, out_id.num_outputs);
|
|
|
|
|
loopback(nsamps, in_id, out_id, input, output);
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_CHECK_EQUAL_COLLECTIONS(
|
|
|
|
|
input.begin(), input.end(), output.begin(), output.end());
|
2015-01-15 15:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_u8_and_u8)
|
|
|
|
|
{
|
2015-01-15 15:23:12 +00:00
|
|
|
convert::id_type id;
|
|
|
|
|
id.input_format = "u8";
|
2019-01-14 18:35:25 +00:00
|
|
|
id.num_inputs = 1;
|
|
|
|
|
id.num_outputs = 1;
|
2015-01-15 15:23:12 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
2015-01-15 15:23:12 +00:00
|
|
|
id.output_format = "u8_item32_le";
|
2019-01-14 18:35:25 +00:00
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
2015-01-15 15:23:12 +00:00
|
|
|
test_convert_types_u8(nsamps, id);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
2015-01-15 15:23:12 +00:00
|
|
|
id.output_format = "u8_item32_be";
|
2019-01-14 18:35:25 +00:00
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
2015-01-15 15:23:12 +00:00
|
|
|
test_convert_types_u8(nsamps, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-09-01 23:00:31 +00:00
|
|
|
|
2019-07-18 21:36:14 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_u8_and_u8_chdr)
|
|
|
|
|
{
|
|
|
|
|
convert::id_type id;
|
|
|
|
|
id.input_format = "u8";
|
|
|
|
|
id.output_format = "u8_chdr";
|
|
|
|
|
id.num_inputs = 1;
|
|
|
|
|
id.num_outputs = 1;
|
|
|
|
|
|
|
|
|
|
// try various lengths to test edge cases
|
|
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
|
|
|
|
test_convert_types_u8(nsamps, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-01 23:00:31 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* Test s8 conversion
|
|
|
|
|
**********************************************************************/
|
2019-01-14 18:35:25 +00:00
|
|
|
static void test_convert_types_s8(size_t nsamps, convert::id_type& id)
|
|
|
|
|
{
|
|
|
|
|
// fill the input samples
|
2016-10-31 21:30:52 +00:00
|
|
|
std::vector<int8_t> input(nsamps), output(nsamps);
|
2019-01-14 18:35:25 +00:00
|
|
|
for (int8_t& in : input)
|
|
|
|
|
in = int8_t(std::rand() & 0xFF);
|
2015-09-01 23:00:31 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// run the loopback and test
|
|
|
|
|
convert::id_type in_id = id;
|
2015-09-01 23:00:31 +00:00
|
|
|
convert::id_type out_id = id;
|
|
|
|
|
std::swap(out_id.input_format, out_id.output_format);
|
|
|
|
|
std::swap(out_id.num_inputs, out_id.num_outputs);
|
|
|
|
|
loopback(nsamps, in_id, out_id, input, output);
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_CHECK_EQUAL_COLLECTIONS(
|
|
|
|
|
input.begin(), input.end(), output.begin(), output.end());
|
2015-09-01 23:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_s8_and_s8)
|
|
|
|
|
{
|
2015-09-01 23:00:31 +00:00
|
|
|
convert::id_type id;
|
|
|
|
|
id.input_format = "s8";
|
2019-01-14 18:35:25 +00:00
|
|
|
id.num_inputs = 1;
|
|
|
|
|
id.num_outputs = 1;
|
2015-09-01 23:00:31 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
2015-09-01 23:00:31 +00:00
|
|
|
id.output_format = "s8_item32_le";
|
2019-01-14 18:35:25 +00:00
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
2015-09-01 23:00:31 +00:00
|
|
|
test_convert_types_s8(nsamps, id);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
2015-09-01 23:00:31 +00:00
|
|
|
id.output_format = "s8_item32_be";
|
2019-01-14 18:35:25 +00:00
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
2015-09-01 23:00:31 +00:00
|
|
|
test_convert_types_s8(nsamps, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-18 21:36:14 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_s8_and_s8_chdr)
|
|
|
|
|
{
|
|
|
|
|
convert::id_type id;
|
|
|
|
|
id.input_format = "s8";
|
|
|
|
|
id.output_format = "s8_chdr";
|
|
|
|
|
id.num_inputs = 1;
|
|
|
|
|
id.num_outputs = 1;
|
|
|
|
|
|
|
|
|
|
// try various lengths to test edge cases
|
|
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
|
|
|
|
test_convert_types_s8(nsamps, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-01 23:00:31 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* Test s16 conversion
|
|
|
|
|
**********************************************************************/
|
2019-01-14 18:35:25 +00:00
|
|
|
static void test_convert_types_s16(size_t nsamps, convert::id_type& id)
|
|
|
|
|
{
|
|
|
|
|
// fill the input samples
|
2016-10-31 21:30:52 +00:00
|
|
|
std::vector<int16_t> input(nsamps), output(nsamps);
|
2019-01-14 18:35:25 +00:00
|
|
|
for (int16_t& in : input)
|
|
|
|
|
in = int16_t(std::rand() & 0xFFFF);
|
2015-09-01 23:00:31 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// run the loopback and test
|
|
|
|
|
convert::id_type in_id = id;
|
2015-09-01 23:00:31 +00:00
|
|
|
convert::id_type out_id = id;
|
|
|
|
|
std::swap(out_id.input_format, out_id.output_format);
|
|
|
|
|
std::swap(out_id.num_inputs, out_id.num_outputs);
|
|
|
|
|
loopback(nsamps, in_id, out_id, input, output);
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_CHECK_EQUAL_COLLECTIONS(
|
|
|
|
|
input.begin(), input.end(), output.begin(), output.end());
|
2015-09-01 23:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_s16_and_s16)
|
|
|
|
|
{
|
2015-09-01 23:00:31 +00:00
|
|
|
convert::id_type id;
|
|
|
|
|
id.input_format = "s16";
|
2019-01-14 18:35:25 +00:00
|
|
|
id.num_inputs = 1;
|
|
|
|
|
id.num_outputs = 1;
|
2015-09-01 23:00:31 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
2015-09-01 23:00:31 +00:00
|
|
|
id.output_format = "s16_item32_le";
|
2019-01-14 18:35:25 +00:00
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
2015-09-01 23:00:31 +00:00
|
|
|
test_convert_types_s16(nsamps, id);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
2015-09-01 23:00:31 +00:00
|
|
|
id.output_format = "s16_item32_be";
|
2019-01-14 18:35:25 +00:00
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
2015-09-01 23:00:31 +00:00
|
|
|
test_convert_types_s16(nsamps, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-18 21:36:14 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_s16_and_s16_chdr)
|
|
|
|
|
{
|
|
|
|
|
convert::id_type id;
|
|
|
|
|
id.input_format = "s16";
|
|
|
|
|
id.output_format = "s16_chdr";
|
|
|
|
|
id.num_inputs = 1;
|
|
|
|
|
id.num_outputs = 1;
|
|
|
|
|
|
|
|
|
|
// try various lengths to test edge cases
|
|
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
|
|
|
|
test_convert_types_s16(nsamps, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-01 23:00:31 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* Test fc32 -> fc32 conversion
|
|
|
|
|
**********************************************************************/
|
2019-01-14 18:35:25 +00:00
|
|
|
static void test_convert_types_fc32(size_t nsamps, convert::id_type& id)
|
|
|
|
|
{
|
|
|
|
|
// fill the input samples
|
|
|
|
|
std::vector<std::complex<float>> input(nsamps), output(nsamps);
|
|
|
|
|
for (fc32_t& in : input)
|
|
|
|
|
in = fc32_t((std::rand() / float(RAND_MAX / 2)) - 1,
|
|
|
|
|
(std::rand() / float(RAND_MAX / 2)) - 1);
|
|
|
|
|
|
|
|
|
|
// run the loopback and test
|
|
|
|
|
convert::id_type in_id = id;
|
2015-09-01 23:00:31 +00:00
|
|
|
convert::id_type out_id = id;
|
|
|
|
|
std::swap(out_id.input_format, out_id.output_format);
|
|
|
|
|
std::swap(out_id.num_inputs, out_id.num_outputs);
|
|
|
|
|
loopback(nsamps, in_id, out_id, input, output);
|
2019-01-14 18:35:25 +00:00
|
|
|
for (size_t i = 0; i < nsamps; i++) {
|
|
|
|
|
MY_CHECK_CLOSE(input[i].real(), output[i].real(), float(1. / (1 << 16)));
|
|
|
|
|
MY_CHECK_CLOSE(input[i].imag(), output[i].imag(), float(1. / (1 << 16)));
|
2017-07-06 21:04:17 +00:00
|
|
|
}
|
2015-09-01 23:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_fc32_and_fc32)
|
|
|
|
|
{
|
2015-09-01 23:00:31 +00:00
|
|
|
convert::id_type id;
|
|
|
|
|
id.input_format = "fc32";
|
2019-01-14 18:35:25 +00:00
|
|
|
id.num_inputs = 1;
|
|
|
|
|
id.num_outputs = 1;
|
2015-09-01 23:00:31 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
2015-09-01 23:00:31 +00:00
|
|
|
id.output_format = "fc32_item32_le";
|
2019-01-14 18:35:25 +00:00
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
2015-09-01 23:00:31 +00:00
|
|
|
test_convert_types_fc32(nsamps, id);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
2015-09-01 23:00:31 +00:00
|
|
|
id.output_format = "fc32_item32_be";
|
2019-01-14 18:35:25 +00:00
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
2015-09-01 23:00:31 +00:00
|
|
|
test_convert_types_fc32(nsamps, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-18 21:36:14 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_convert_types_fc32_and_fc32_chdr)
|
2019-01-14 18:35:25 +00:00
|
|
|
{
|
2015-09-01 23:00:31 +00:00
|
|
|
convert::id_type id;
|
2019-07-18 21:36:14 +00:00
|
|
|
id.input_format = "fc32";
|
|
|
|
|
id.output_format = "fc32_chdr";
|
2019-01-14 18:35:25 +00:00
|
|
|
id.num_inputs = 1;
|
|
|
|
|
id.num_outputs = 1;
|
2015-09-01 23:00:31 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// try various lengths to test edge cases
|
|
|
|
|
for (size_t nsamps = 1; nsamps < 16; nsamps++) {
|
2019-07-18 21:36:14 +00:00
|
|
|
test_convert_types_fc32(nsamps, id);
|
2015-09-01 23:00:31 +00:00
|
|
|
}
|
|
|
|
|
}
|