From 72359ea15846ab87c781ab4d072f694e97cc3cd1 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 17 Jan 2012 13:42:37 -0800 Subject: uhd: implement convert_sc8to_sc16 table w/ scalar --- host/lib/convert/convert_with_tables.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'host/lib/convert') diff --git a/host/lib/convert/convert_with_tables.cpp b/host/lib/convert/convert_with_tables.cpp index c45415d5d..c033a2959 100644 --- a/host/lib/convert/convert_with_tables.cpp +++ b/host/lib/convert/convert_with_tables.cpp @@ -17,6 +17,7 @@ #include "convert_common.hpp" #include +#include #include using namespace uhd::convert; @@ -68,6 +69,19 @@ public: convert_sc8_item32_1_to_fcxx_1(void): _table(sc16_table_len){} void set_scalar(const double scalar){ + + //special case, this is converts sc8 to sc16, + //use the scale-factor but no normalization + if (sizeof(type) == sizeof(s16_t)){ + for (size_t i = 0; i < sc16_table_len; i++){ + const boost::uint16_t val = tohost(boost::uint16_t(i & 0xffff)); + const type real = type(boost::math::iround(boost::int8_t(val >> 8)*scalar*32767)); + const type imag = type(boost::math::iround(boost::int8_t(val >> 0)*scalar*32767)); + _table[i] = std::complex(real, imag); + } + return; + } + for (size_t i = 0; i < sc16_table_len; i++){ const boost::uint16_t val = tohost(boost::uint16_t(i & 0xffff)); const type real = type(boost::int8_t(val >> 8)*scalar); @@ -149,6 +163,14 @@ static converter::sptr make_convert_sc8_item32_le_1_to_fc64_1(void){ return converter::sptr(new convert_sc8_item32_1_to_fcxx_1()); } +static converter::sptr make_convert_sc8_item32_be_1_to_sc16_1(void){ + return converter::sptr(new convert_sc8_item32_1_to_fcxx_1()); +} + +static converter::sptr make_convert_sc8_item32_le_1_to_sc16_1(void){ + return converter::sptr(new convert_sc8_item32_1_to_fcxx_1()); +} + UHD_STATIC_BLOCK(register_convert_sc16_item32_1_to_fcxx_1){ uhd::convert::id_type id; id.num_inputs = 1; @@ -185,4 +207,12 @@ UHD_STATIC_BLOCK(register_convert_sc16_item32_1_to_fcxx_1){ id.output_format = "fc64"; id.input_format = "sc8_item32_le"; uhd::convert::register_converter(id, &make_convert_sc8_item32_le_1_to_fc64_1, PRIORITY_TABLE); + + id.output_format = "sc16"; + id.input_format = "sc8_item32_be"; + uhd::convert::register_converter(id, &make_convert_sc8_item32_be_1_to_sc16_1, PRIORITY_TABLE); + + id.output_format = "sc16"; + id.input_format = "sc8_item32_le"; + uhd::convert::register_converter(id, &make_convert_sc8_item32_le_1_to_sc16_1, PRIORITY_TABLE); } -- cgit v1.2.3