summaryrefslogtreecommitdiffstats
path: root/host/lib/convert
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2012-01-30 22:23:38 -0800
committerJosh Blum <josh@joshknows.com>2012-01-31 14:56:31 -0800
commitd46c176af34b728fd43b3dd46485b38623a7335e (patch)
tree4c93a5dc27c6c5213c858f6c4312d1195a44e32d /host/lib/convert
parent781cafa8717f00b883a4543b4a9150060691eee3 (diff)
downloaduhd-d46c176af34b728fd43b3dd46485b38623a7335e.tar.gz
uhd-d46c176af34b728fd43b3dd46485b38623a7335e.tar.bz2
uhd-d46c176af34b728fd43b3dd46485b38623a7335e.zip
dsp rework: tx trailer, scaling work (peak)
Diffstat (limited to 'host/lib/convert')
-rw-r--r--host/lib/convert/convert_common.hpp48
-rw-r--r--host/lib/convert/convert_with_tables.cpp21
-rw-r--r--host/lib/convert/gen_convert_general.py16
3 files changed, 72 insertions, 13 deletions
diff --git a/host/lib/convert/convert_common.hpp b/host/lib/convert/convert_common.hpp
index 699d6301b..aab59de4b 100644
--- a/host/lib/convert/convert_common.hpp
+++ b/host/lib/convert/convert_common.hpp
@@ -190,4 +190,52 @@ static UHD_INLINE void item32_sc8_to_fc64(item32_t item, fc64_t &out0, fc64_t &o
);
}
+/***********************************************************************
+ * Convert complex char to items32 sc8 buffer
+ **********************************************************************/
+static UHD_INLINE item32_t sc8_to_item32_sc8(sc8_t in0, sc8_t in1, double){
+ return
+ (item32_t(boost::uint8_t(in0.real())) << 8) |
+ (item32_t(boost::uint8_t(in0.imag())) << 0) |
+ (item32_t(boost::uint8_t(in1.real())) << 24) |
+ (item32_t(boost::uint8_t(in1.imag())) << 16)
+ ;
+}
+
+/***********************************************************************
+ * Convert complex short to items32 sc8 buffer
+ **********************************************************************/
+static UHD_INLINE item32_t sc16_to_item32_sc8(sc16_t in0, sc16_t in1, double){
+ return
+ (item32_t(boost::uint8_t(in0.real())) << 8) |
+ (item32_t(boost::uint8_t(in0.imag())) << 0) |
+ (item32_t(boost::uint8_t(in1.real())) << 24) |
+ (item32_t(boost::uint8_t(in1.imag())) << 16)
+ ;
+}
+
+/***********************************************************************
+ * Convert complex float to items32 sc8 buffer
+ **********************************************************************/
+static UHD_INLINE item32_t fc32_to_item32_sc8(fc32_t in0, fc32_t in1, double scale_factor){
+ return
+ (item32_t(boost::uint8_t(in0.real()*float(scale_factor))) << 8) |
+ (item32_t(boost::uint8_t(in0.imag()*float(scale_factor))) << 0) |
+ (item32_t(boost::uint8_t(in1.real()*float(scale_factor))) << 24) |
+ (item32_t(boost::uint8_t(in1.imag()*float(scale_factor))) << 16)
+ ;
+}
+
+/***********************************************************************
+ * Convert complex double to items32 sc8 buffer
+ **********************************************************************/
+static UHD_INLINE item32_t fc64_to_item32_sc8(fc64_t in0, fc64_t in1, double scale_factor){
+ return
+ (item32_t(boost::uint8_t(in0.real()*(scale_factor))) << 8) |
+ (item32_t(boost::uint8_t(in0.imag()*(scale_factor))) << 0) |
+ (item32_t(boost::uint8_t(in1.real()*(scale_factor))) << 24) |
+ (item32_t(boost::uint8_t(in1.imag()*(scale_factor))) << 16)
+ ;
+}
+
#endif /* INCLUDED_LIBUHD_CONVERT_COMMON_HPP */
diff --git a/host/lib/convert/convert_with_tables.cpp b/host/lib/convert/convert_with_tables.cpp
index c033a2959..2379739a7 100644
--- a/host/lib/convert/convert_with_tables.cpp
+++ b/host/lib/convert/convert_with_tables.cpp
@@ -68,24 +68,19 @@ class convert_sc8_item32_1_to_fcxx_1 : public converter{
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
+ //special case for sc16 type, 32767 undoes float normalization
+ static type conv(const boost::int8_t &num, const double scalar){
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;
+ return type(boost::math::iround(num*scalar*32767));
}
+ return type(num*scalar);
+ }
+ void set_scalar(const double scalar){
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);
- const type imag = type(boost::int8_t(val >> 0)*scalar);
+ const type real = conv(boost::int8_t(val >> 8), scalar);
+ const type imag = conv(boost::int8_t(val >> 0), scalar);
_table[i] = std::complex<type>(real, imag);
}
}
diff --git a/host/lib/convert/gen_convert_general.py b/host/lib/convert/gen_convert_general.py
index b8d64aa4b..a6ae3f810 100644
--- a/host/lib/convert/gen_convert_general.py
+++ b/host/lib/convert/gen_convert_general.py
@@ -92,6 +92,22 @@ DECLARE_CONVERTER(sc8_item32_$(end), 1, $(cpu_type), 1, PRIORITY_GENERAL){
item32_sc8_to_$(cpu_type)(item_n, output[num_samps-1], dummy, scale_factor);
}
}
+
+DECLARE_CONVERTER($(cpu_type), 1, sc8_item32_$(end), 1, PRIORITY_GENERAL){
+ const $(cpu_type)_t *input = reinterpret_cast<const $(cpu_type)_t *>(inputs[0]);
+ item32_t *output = reinterpret_cast<item32_t *>(outputs[0]);
+
+ const size_t num_pairs = nsamps/2;
+ for (size_t i = 0, j = 0; i < num_pairs; i++, j+=2){
+ const item32_t item = $(cpu_type)_to_item32_sc8(input[j], input[j+1], scale_factor);
+ output[i] = $(to_wire)(item);
+ }
+
+ if (nsamps != num_pairs*2){
+ const item32_t item = $(cpu_type)_to_item32_sc8(input[nsamps-1], 0, scale_factor);
+ output[num_pairs] = $(to_wire)(item);
+ }
+}
"""
TMPL_CONV_USRP1_COMPLEX = """