summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-02-03 16:45:34 -0800
committerJosh Blum <josh@joshknows.com>2011-02-03 16:45:34 -0800
commit43b19815fec253dc7e5538329f9fe1363f007b8a (patch)
tree152724e647f8986868ef521154720ec9a5b8544d
parent1c8626e40cc9e5243cea0956c6d35d9d96c08d38 (diff)
downloaduhd-43b19815fec253dc7e5538329f9fe1363f007b8a.tar.gz
uhd-43b19815fec253dc7e5538329f9fe1363f007b8a.tar.bz2
uhd-43b19815fec253dc7e5538329f9fe1363f007b8a.zip
uhd: added io type and conversion for complex64 (its not really useful)
-rw-r--r--host/include/uhd/types/io_type.hpp2
-rw-r--r--host/lib/convert/convert_common.hpp25
-rw-r--r--host/lib/convert/gen_convert_general.py2
-rw-r--r--host/lib/convert/gen_convert_pred.py16
-rw-r--r--host/lib/types/types.cpp1
-rw-r--r--host/tests/convert_test.cpp46
6 files changed, 77 insertions, 15 deletions
diff --git a/host/include/uhd/types/io_type.hpp b/host/include/uhd/types/io_type.hpp
index ec1b9c056..990d701f9 100644
--- a/host/include/uhd/types/io_type.hpp
+++ b/host/include/uhd/types/io_type.hpp
@@ -35,6 +35,8 @@ namespace uhd{
enum tid_t{
//! Custom type (technically unsupported by implementation)
CUSTOM_TYPE = '?',
+ //! Complex floating point (64-bit floats) range [-1.0, +1.0]
+ COMPLEX_FLOAT64 = 'd',
//! Complex floating point (32-bit floats) range [-1.0, +1.0]
COMPLEX_FLOAT32 = 'f',
//! Complex signed integer (16-bit integers) range [-32768, +32767]
diff --git a/host/lib/convert/convert_common.hpp b/host/lib/convert/convert_common.hpp
index 1a653a56f..c6ba1fcf9 100644
--- a/host/lib/convert/convert_common.hpp
+++ b/host/lib/convert/convert_common.hpp
@@ -41,8 +41,10 @@
/***********************************************************************
* Typedefs
**********************************************************************/
+typedef std::complex<double> fc64_t;
typedef std::complex<float> fc32_t;
typedef std::complex<boost::int16_t> sc16_t;
+typedef std::complex<boost::int8_t> sc8_t;
typedef boost::uint32_t item32_t;
/***********************************************************************
@@ -87,4 +89,27 @@ static UHD_INLINE fc32_t item32_to_fc32(item32_t item){
);
}
+/***********************************************************************
+ * Convert complex double buffer to items32 (no swap)
+ **********************************************************************/
+static const double shorts_per_double = double(32767);
+
+static UHD_INLINE item32_t fc64_to_item32(fc64_t num){
+ boost::uint16_t real = boost::int16_t(num.real()*shorts_per_double);
+ boost::uint16_t imag = boost::int16_t(num.imag()*shorts_per_double);
+ return (item32_t(real) << 16) | (item32_t(imag) << 0);
+}
+
+/***********************************************************************
+ * Convert items32 buffer to complex double
+ **********************************************************************/
+static const double doubles_per_short = double(1.0/shorts_per_double);
+
+static UHD_INLINE fc64_t item32_to_fc64(item32_t item){
+ return fc64_t(
+ float(boost::int16_t(item >> 16)*doubles_per_short),
+ float(boost::int16_t(item >> 0)*doubles_per_short)
+ );
+}
+
#endif /* INCLUDED_LIBUHD_CONVERT_COMMON_HPP */
diff --git a/host/lib/convert/gen_convert_general.py b/host/lib/convert/gen_convert_general.py
index 47c4cd7d0..f03448047 100644
--- a/host/lib/convert/gen_convert_general.py
+++ b/host/lib/convert/gen_convert_general.py
@@ -85,7 +85,7 @@ if __name__ == '__main__':
output = parse_tmpl(TMPL_HEADER, file=file)
for width in 1, 2, 3, 4:
for swap, swap_fcn in (('nswap', ''), ('bswap', 'uhd::byteswap')):
- for cpu_type in 'fc32', 'sc16':
+ for cpu_type in 'fc64', 'fc32', 'sc16':
output += parse_tmpl(
TMPL_CONV_TO_FROM_ITEM32_1 if width == 1 else TMPL_CONV_TO_FROM_ITEM32_X,
width=width, swap=swap, swap_fcn=swap_fcn, cpu_type=cpu_type
diff --git a/host/lib/convert/gen_convert_pred.py b/host/lib/convert/gen_convert_pred.py
index 1d573bf1a..fea7db4cc 100644
--- a/host/lib/convert/gen_convert_pred.py
+++ b/host/lib/convert/gen_convert_pred.py
@@ -69,8 +69,10 @@ pred_type make_pred(const std::string &markup, dir_type &dir){
dir = DIR_OTW_TO_CPU;
}
- if (cpu_type == "fc32") pred |= $ph.fc32_p;
+ if (cpu_type == "fc64") pred |= $ph.fc64_p;
+ else if (cpu_type == "fc32") pred |= $ph.fc32_p;
else if (cpu_type == "sc16") pred |= $ph.sc16_p;
+ else if (cpu_type == "sc8") pred |= $ph.sc8_p;
else throw pred_error("unhandled io type " + cpu_type);
if (otw_type == "item32") pred |= $ph.item32_p;
@@ -127,6 +129,8 @@ UHD_INLINE pred_type make_pred(
switch(io_type.tid){
case io_type_t::COMPLEX_FLOAT32: pred |= $ph.fc32_p; break;
case io_type_t::COMPLEX_INT16: pred |= $ph.sc16_p; break;
+ //case io_type_t::COMPLEX_INT8: pred |= $ph.sc8_p; break;
+ case io_type_t::COMPLEX_FLOAT64: pred |= $ph.fc64_p; break;
default: throw pred_error("unhandled io type id");
}
@@ -150,12 +154,14 @@ class ph:
bswap_p = 0b00001
nswap_p = 0b00000
item32_p = 0b00000
+ sc8_p = 0b00000
sc16_p = 0b00010
- fc32_p = 0b00000
+ fc32_p = 0b00100
+ fc64_p = 0b00110
chan1_p = 0b00000
- chan2_p = 0b00100
- chan3_p = 0b01000
- chan4_p = 0b01100
+ chan2_p = 0b01000
+ chan3_p = 0b10000
+ chan4_p = 0b11000
if __name__ == '__main__':
import sys, os
diff --git a/host/lib/types/types.cpp b/host/lib/types/types.cpp
index 34d5947eb..c1be2ff6d 100644
--- a/host/lib/types/types.cpp
+++ b/host/lib/types/types.cpp
@@ -68,6 +68,7 @@ otw_type_t::otw_type_t(void):
**********************************************************************/
static size_t tid_to_size(io_type_t::tid_t tid){
switch(tid){
+ case io_type_t::COMPLEX_FLOAT64: return sizeof(std::complex<double>);
case io_type_t::COMPLEX_FLOAT32: return sizeof(std::complex<float>);
case io_type_t::COMPLEX_INT16: return sizeof(std::complex<boost::int16_t>);
case io_type_t::COMPLEX_INT8: return sizeof(std::complex<boost::int8_t>);
diff --git a/host/tests/convert_test.cpp b/host/tests/convert_test.cpp
index 5f2aaf3d1..d3c235e9b 100644
--- a/host/tests/convert_test.cpp
+++ b/host/tests/convert_test.cpp
@@ -29,6 +29,7 @@ using namespace uhd;
//typedefs for complex types
typedef std::complex<boost::int16_t> sc16_t;
typedef std::complex<float> fc32_t;
+typedef std::complex<double> fc64_t;
#define MY_CHECK_CLOSE(a, b, f) if ((std::abs(a) > (f) and std::abs(b) > (f))) \
BOOST_CHECK_CLOSE_FRACTION(a, b, f)
@@ -109,23 +110,26 @@ BOOST_AUTO_TEST_CASE(test_convert_types_le_sc16){
/***********************************************************************
* Test float conversion
**********************************************************************/
-static void test_convert_types_fc32(
+template <typename data_type>
+static void test_convert_types_for_floats(
size_t nsamps,
const io_type_t &io_type,
const otw_type_t &otw_type
){
+ typedef typename data_type::value_type value_type;
+
//fill the input samples
- std::vector<fc32_t> input(nsamps), output(nsamps);
- BOOST_FOREACH(fc32_t &in, input) in = fc32_t(
- (std::rand()/float(RAND_MAX/2)) - 1,
- (std::rand()/float(RAND_MAX/2)) - 1
+ std::vector<data_type> input(nsamps), output(nsamps);
+ BOOST_FOREACH(data_type &in, input) in = data_type(
+ (std::rand()/value_type(RAND_MAX/2)) - 1,
+ (std::rand()/value_type(RAND_MAX/2)) - 1
);
//run the loopback and test
loopback(nsamps, io_type, otw_type, input, output);
for (size_t i = 0; i < nsamps; i++){
- MY_CHECK_CLOSE(input[i].real(), output[i].real(), float(0.01));
- MY_CHECK_CLOSE(input[i].imag(), output[i].imag(), float(0.01));
+ MY_CHECK_CLOSE(input[i].real(), output[i].real(), value_type(0.01));
+ MY_CHECK_CLOSE(input[i].imag(), output[i].imag(), value_type(0.01));
}
}
@@ -137,7 +141,7 @@ BOOST_AUTO_TEST_CASE(test_convert_types_be_fc32){
//try various lengths to test edge cases
for (size_t nsamps = 1; nsamps < 16; nsamps++){
- test_convert_types_fc32(nsamps, io_type, otw_type);
+ test_convert_types_for_floats<fc32_t>(nsamps, io_type, otw_type);
}
}
@@ -149,7 +153,31 @@ BOOST_AUTO_TEST_CASE(test_convert_types_le_fc32){
//try various lengths to test edge cases
for (size_t nsamps = 1; nsamps < 16; nsamps++){
- test_convert_types_fc32(nsamps, io_type, otw_type);
+ test_convert_types_for_floats<fc32_t>(nsamps, io_type, otw_type);
+ }
+}
+
+BOOST_AUTO_TEST_CASE(test_convert_types_be_fc64){
+ io_type_t io_type(io_type_t::COMPLEX_FLOAT64);
+ otw_type_t otw_type;
+ otw_type.byteorder = otw_type_t::BO_BIG_ENDIAN;
+ otw_type.width = 16;
+
+ //try various lengths to test edge cases
+ for (size_t nsamps = 1; nsamps < 16; nsamps++){
+ test_convert_types_for_floats<fc64_t>(nsamps, io_type, otw_type);
+ }
+}
+
+BOOST_AUTO_TEST_CASE(test_convert_types_le_fc64){
+ io_type_t io_type(io_type_t::COMPLEX_FLOAT64);
+ otw_type_t otw_type;
+ otw_type.byteorder = otw_type_t::BO_LITTLE_ENDIAN;
+ otw_type.width = 16;
+
+ //try various lengths to test edge cases
+ for (size_t nsamps = 1; nsamps < 16; nsamps++){
+ test_convert_types_for_floats<fc64_t>(nsamps, io_type, otw_type);
}
}