aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2012-01-17 13:42:37 -0800
committerJosh Blum <josh@joshknows.com>2012-01-31 14:56:31 -0800
commit72359ea15846ab87c781ab4d072f694e97cc3cd1 (patch)
treeaf28f7a3626534e7c4b373c2fe837282479bc73d /host/lib
parent5b06adb7911727353938df84a0a6b71cda66c95c (diff)
downloaduhd-72359ea15846ab87c781ab4d072f694e97cc3cd1.tar.gz
uhd-72359ea15846ab87c781ab4d072f694e97cc3cd1.tar.bz2
uhd-72359ea15846ab87c781ab4d072f694e97cc3cd1.zip
uhd: implement convert_sc8to_sc16 table w/ scalar
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/convert/convert_with_tables.cpp30
1 files changed, 30 insertions, 0 deletions
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 <uhd/utils/byteswap.hpp>
+#include <boost/math/special_functions/round.hpp>
#include <vector>
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<type>(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<double, uhd::wtohx, SHIFT_PAIR0>());
}
+static converter::sptr make_convert_sc8_item32_be_1_to_sc16_1(void){
+ return converter::sptr(new convert_sc8_item32_1_to_fcxx_1<s16_t, uhd::ntohx, SHIFT_PAIR1>());
+}
+
+static converter::sptr make_convert_sc8_item32_le_1_to_sc16_1(void){
+ return converter::sptr(new convert_sc8_item32_1_to_fcxx_1<s16_t, uhd::wtohx, SHIFT_PAIR0>());
+}
+
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);
}