aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/convert/convert_common.hpp
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-01-04 17:11:52 -0800
committerJosh Blum <josh@joshknows.com>2011-01-04 17:11:52 -0800
commit91790751b614b86393dd7963f1a4476d0e60ed4a (patch)
tree65792ea10b39ecb46d6cb9685ed46ab38e88933f /host/lib/convert/convert_common.hpp
parentea20cc274cdd7ea15df2347e9d1a3539bd819bed (diff)
downloaduhd-91790751b614b86393dd7963f1a4476d0e60ed4a.tar.gz
uhd-91790751b614b86393dd7963f1a4476d0e60ed4a.tar.bz2
uhd-91790751b614b86393dd7963f1a4476d0e60ed4a.zip
uhd: added new convert directory with type conversion registry (needs testing)
Diffstat (limited to 'host/lib/convert/convert_common.hpp')
-rw-r--r--host/lib/convert/convert_common.hpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/host/lib/convert/convert_common.hpp b/host/lib/convert/convert_common.hpp
new file mode 100644
index 000000000..1a653a56f
--- /dev/null
+++ b/host/lib/convert/convert_common.hpp
@@ -0,0 +1,90 @@
+//
+// Copyright 2011 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_LIBUHD_CONVERT_COMMON_HPP
+#define INCLUDED_LIBUHD_CONVERT_COMMON_HPP
+
+#include <uhd/convert.hpp>
+#include <uhd/utils/static.hpp>
+#include <boost/cstdint.hpp>
+#include <complex>
+
+#define DECLARE_CONVERTER(fcn, prio) \
+ static void fcn( \
+ uhd::convert::input_type &inputs, \
+ uhd::convert::output_type &outputs, \
+ size_t nsamps \
+ ); \
+ UHD_STATIC_BLOCK(register_##fcn##_##prio){ \
+ uhd::convert::register_converter(#fcn, fcn, prio); \
+ } \
+ static void fcn( \
+ uhd::convert::input_type &inputs, \
+ uhd::convert::output_type &outputs, \
+ size_t nsamps \
+ )
+
+/***********************************************************************
+ * Typedefs
+ **********************************************************************/
+typedef std::complex<float> fc32_t;
+typedef std::complex<boost::int16_t> sc16_t;
+typedef boost::uint32_t item32_t;
+
+/***********************************************************************
+ * Convert complex short buffer to items32
+ **********************************************************************/
+static UHD_INLINE item32_t sc16_to_item32(sc16_t num){
+ boost::uint16_t real = num.real();
+ boost::uint16_t imag = num.imag();
+ return (item32_t(real) << 16) | (item32_t(imag) << 0);
+}
+
+/***********************************************************************
+ * Convert items32 buffer to complex short
+ **********************************************************************/
+static UHD_INLINE sc16_t item32_to_sc16(item32_t item){
+ return sc16_t(
+ boost::int16_t(item >> 16),
+ boost::int16_t(item >> 0)
+ );
+}
+
+/***********************************************************************
+ * Convert complex float buffer to items32 (no swap)
+ **********************************************************************/
+static const float shorts_per_float = float(32767);
+
+static UHD_INLINE item32_t fc32_to_item32(fc32_t num){
+ boost::uint16_t real = boost::int16_t(num.real()*shorts_per_float);
+ boost::uint16_t imag = boost::int16_t(num.imag()*shorts_per_float);
+ return (item32_t(real) << 16) | (item32_t(imag) << 0);
+}
+
+/***********************************************************************
+ * Convert items32 buffer to complex float
+ **********************************************************************/
+static const float floats_per_short = float(1.0/shorts_per_float);
+
+static UHD_INLINE fc32_t item32_to_fc32(item32_t item){
+ return fc32_t(
+ float(boost::int16_t(item >> 16)*floats_per_short),
+ float(boost::int16_t(item >> 0)*floats_per_short)
+ );
+}
+
+#endif /* INCLUDED_LIBUHD_CONVERT_COMMON_HPP */