summaryrefslogtreecommitdiffstats
path: root/host/lib/convert
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-10-06 18:41:59 -0700
committerJosh Blum <josh@joshknows.com>2011-11-03 20:37:11 -0700
commit4c4f0810ef06be18e989b6933ff236ff97c13dd0 (patch)
treece506b4f259d31d966b847dde9adddf07f09f753 /host/lib/convert
parentde17ef4614c3c14212f239e3c735bfde3f47a68f (diff)
downloaduhd-4c4f0810ef06be18e989b6933ff236ff97c13dd0.tar.gz
uhd-4c4f0810ef06be18e989b6933ff236ff97c13dd0.tar.bz2
uhd-4c4f0810ef06be18e989b6933ff236ff97c13dd0.zip
usrp1: type conversions and 8-bit work
Diffstat (limited to 'host/lib/convert')
-rw-r--r--host/lib/convert/convert_common.hpp12
-rw-r--r--host/lib/convert/gen_convert_general.py102
2 files changed, 89 insertions, 25 deletions
diff --git a/host/lib/convert/convert_common.hpp b/host/lib/convert/convert_common.hpp
index 8c8cc88b0..612fa312b 100644
--- a/host/lib/convert/convert_common.hpp
+++ b/host/lib/convert/convert_common.hpp
@@ -86,19 +86,19 @@ static UHD_INLINE sc16_t item32_to_sc16(item32_t item, double){
/***********************************************************************
* Convert complex float buffer to items32 (no swap)
**********************************************************************/
-static UHD_INLINE item32_t fc32_to_item32(fc32_t num, float scale_factor){
- boost::uint16_t real = boost::int16_t(num.real()*scale_factor);
- boost::uint16_t imag = boost::int16_t(num.imag()*scale_factor);
+static UHD_INLINE item32_t fc32_to_item32(fc32_t num, double scale_factor){
+ boost::uint16_t real = boost::int16_t(num.real()*float(scale_factor));
+ boost::uint16_t imag = boost::int16_t(num.imag()*float(scale_factor));
return (item32_t(real) << 16) | (item32_t(imag) << 0);
}
/***********************************************************************
* Convert items32 buffer to complex float
**********************************************************************/
-static UHD_INLINE fc32_t item32_to_fc32(item32_t item, float scale_factor){
+static UHD_INLINE fc32_t item32_to_fc32(item32_t item, double scale_factor){
return fc32_t(
- float(boost::int16_t(item >> 16)*scale_factor),
- float(boost::int16_t(item >> 0)*scale_factor)
+ float(boost::int16_t(item >> 16)*float(scale_factor)),
+ float(boost::int16_t(item >> 0)*float(scale_factor))
);
}
diff --git a/host/lib/convert/gen_convert_general.py b/host/lib/convert/gen_convert_general.py
index 0d68a4dd3..a5c4d4cb7 100644
--- a/host/lib/convert/gen_convert_general.py
+++ b/host/lib/convert/gen_convert_general.py
@@ -28,13 +28,13 @@ TMPL_HEADER = """
using namespace uhd::convert;
"""
-TMPL_CONV_TO_FROM_ITEM32_1 = """
+TMPL_CONV_GEN2_COMPLEX = """
DECLARE_CONVERTER($(cpu_type), 1, sc16_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]);
for (size_t i = 0; i < nsamps; i++){
- output[i] = $(to_wire)($(cpu_type)_to_item32(input[i], float(scale_factor)));
+ output[i] = $(to_wire)($(cpu_type)_to_item32(input[i], scale_factor));
}
}
@@ -43,33 +43,83 @@ DECLARE_CONVERTER(sc16_item32_$(end), 1, $(cpu_type), 1, PRIORITY_GENERAL){
$(cpu_type)_t *output = reinterpret_cast<$(cpu_type)_t *>(outputs[0]);
for (size_t i = 0; i < nsamps; i++){
- output[i] = item32_to_$(cpu_type)($(to_host)(input[i]), float(scale_factor));
+ output[i] = item32_to_$(cpu_type)($(to_host)(input[i]), scale_factor);
}
}
"""
-TMPL_CONV_TO_FROM_ITEM32_X = """
-DECLARE_CONVERTER($(cpu_type), $(width), sc16_item32_$(end), 1, PRIORITY_GENERAL){
+
+TMPL_CONV_USRP1_COMPLEX = """
+DECLARE_CONVERTER($(cpu_type), $(width), sc16_item16_usrp1, 1, PRIORITY_GENERAL){
#for $w in range($width)
const $(cpu_type)_t *input$(w) = reinterpret_cast<const $(cpu_type)_t *>(inputs[$(w)]);
#end for
- item32_t *output = reinterpret_cast<item32_t *>(outputs[0]);
+ boost::uint16_t *output = reinterpret_cast<boost::uint16_t *>(outputs[0]);
+
+ if (scale_factor == 0){} //avoids unused warning
for (size_t i = 0, j = 0; i < nsamps; i++){
#for $w in range($width)
- output[j++] = $(to_wire)($(cpu_type)_to_item32(input$(w)[i], float(scale_factor)));
+ output[j++] = $(to_wire)(boost::int16_t(input$(w)[i].real()$(do_scale)));
+ output[j++] = $(to_wire)(boost::int16_t(input$(w)[i].imag()$(do_scale)));
#end for
}
}
-DECLARE_CONVERTER(sc16_item32_$(end), 1, $(cpu_type), $(width), PRIORITY_GENERAL){
- const item32_t *input = reinterpret_cast<const item32_t *>(inputs[0]);
+DECLARE_CONVERTER(sc16_item16_usrp1, 1, $(cpu_type), $(width), PRIORITY_GENERAL){
+ const boost::uint16_t *input = reinterpret_cast<const boost::uint16_t *>(inputs[0]);
#for $w in range($width)
$(cpu_type)_t *output$(w) = reinterpret_cast<$(cpu_type)_t *>(outputs[$(w)]);
#end for
+ if (scale_factor == 0){} //avoids unused warning
+
for (size_t i = 0, j = 0; i < nsamps; i++){
#for $w in range($width)
- output$(w)[i] = item32_to_$(cpu_type)($(to_host)(input[j++]), float(scale_factor));
+ output$(w)[i] = $(cpu_type)_t(
+ boost::int16_t($(to_host)(input[j+0]))$(do_scale),
+ boost::int16_t($(to_host)(input[j+1]))$(do_scale)
+ );
+ j += 2;
+ #end for
+ }
+}
+
+DECLARE_CONVERTER($(cpu_type), $(width), sc8_item16_usrp1, 1, PRIORITY_GENERAL){
+ #for $w in range($width)
+ const $(cpu_type)_t *input$(w) = reinterpret_cast<const $(cpu_type)_t *>(inputs[$(w)]);
+ #end for
+ boost::uint16_t *output = reinterpret_cast<boost::uint16_t *>(outputs[0]);
+
+ if (scale_factor == 0){} //avoids unused warning
+
+ for (size_t i = 0, j = 0; i < nsamps; i++){
+ #for $w in range($width)
+ {
+ const boost::uint8_t real = boost::int8_t(input$(w)[i].real()$(do_scale));
+ const boost::uint8_t imag = boost::int8_t(input$(w)[i].imag()$(do_scale));
+ output[j++] = $(to_wire)((boost::uint16_t(imag) << 8) | real);
+ }
+ #end for
+ }
+}
+
+DECLARE_CONVERTER(sc8_item16_usrp1, 1, $(cpu_type), $(width), PRIORITY_GENERAL){
+ const boost::uint16_t *input = reinterpret_cast<const boost::uint16_t *>(inputs[0]);
+ #for $w in range($width)
+ $(cpu_type)_t *output$(w) = reinterpret_cast<$(cpu_type)_t *>(outputs[$(w)]);
+ #end for
+
+ if (scale_factor == 0){} //avoids unused warning
+
+ for (size_t i = 0, j = 0; i < nsamps; i++){
+ #for $w in range($width)
+ {
+ const boost::uint16_t num = $(to_host)(input[j++]);
+ output$(w)[i] = $(cpu_type)_t(
+ boost::int8_t(num)$(do_scale),
+ boost::int8_t(num >> 8)$(do_scale)
+ );
+ }
#end for
}
}
@@ -83,14 +133,28 @@ if __name__ == '__main__':
import sys, os
file = os.path.basename(__file__)
output = parse_tmpl(TMPL_HEADER, file=file)
- for width in 1, 2, 3, 4:
- for end, to_host, to_wire in (
- ('be', 'uhd::ntohx', 'uhd::htonx'),
- ('le', 'uhd::wtohx', 'uhd::htowx'),
+
+ #generate complex converters for all gen2 platforms
+ for end, to_host, to_wire in (
+ ('be', 'uhd::ntohx', 'uhd::htonx'),
+ ('le', 'uhd::wtohx', 'uhd::htowx'),
+ ):
+ for cpu_type in 'fc64', 'fc32', 'sc16':
+ output += parse_tmpl(
+ TMPL_CONV_GEN2_COMPLEX,
+ end=end, to_host=to_host, to_wire=to_wire, cpu_type=cpu_type
+ )
+
+ #generate complex converters for usrp1 format
+ for width in 1, 2, 4:
+ for cpu_type, do_scale in (
+ ('fc64', '*scale_factor'),
+ ('fc32', '*float(scale_factor)'),
+ ('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, end=end, to_host=to_host, to_wire=to_wire, cpu_type=cpu_type
- )
+ output += parse_tmpl(
+ TMPL_CONV_USRP1_COMPLEX,
+ width=width, to_host='uhd::wtohx', to_wire='uhd::htowx',
+ cpu_type=cpu_type, do_scale=do_scale
+ )
open(sys.argv[1], 'w').write(output)