diff options
author | Josh Blum <josh@joshknows.com> | 2011-02-03 18:51:42 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2011-02-03 18:51:42 -0800 |
commit | d6c52af6a8ac2e2a85942116768cf69971aac48a (patch) | |
tree | 58f90b7da55eda0317ac1343ad7878c9adfdc631 /host/lib/convert/convert_common.hpp | |
parent | 5d459d1cb09cdce0c1fd4d7e7d0259310921b94f (diff) | |
parent | 43b19815fec253dc7e5538329f9fe1363f007b8a (diff) | |
download | uhd-d6c52af6a8ac2e2a85942116768cf69971aac48a.tar.gz uhd-d6c52af6a8ac2e2a85942116768cf69971aac48a.tar.bz2 uhd-d6c52af6a8ac2e2a85942116768cf69971aac48a.zip |
Merge branch 'convert_fc64'
Diffstat (limited to 'host/lib/convert/convert_common.hpp')
-rw-r--r-- | host/lib/convert/convert_common.hpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/host/lib/convert/convert_common.hpp b/host/lib/convert/convert_common.hpp index 1a653a56f..c6ba1fcf9 100644 --- a/host/lib/convert/convert_common.hpp +++ b/host/lib/convert/convert_common.hpp @@ -41,8 +41,10 @@ /*********************************************************************** * Typedefs **********************************************************************/ +typedef std::complex<double> fc64_t; typedef std::complex<float> fc32_t; typedef std::complex<boost::int16_t> sc16_t; +typedef std::complex<boost::int8_t> sc8_t; typedef boost::uint32_t item32_t; /*********************************************************************** @@ -87,4 +89,27 @@ static UHD_INLINE fc32_t item32_to_fc32(item32_t item){ ); } +/*********************************************************************** + * Convert complex double buffer to items32 (no swap) + **********************************************************************/ +static const double shorts_per_double = double(32767); + +static UHD_INLINE item32_t fc64_to_item32(fc64_t num){ + boost::uint16_t real = boost::int16_t(num.real()*shorts_per_double); + boost::uint16_t imag = boost::int16_t(num.imag()*shorts_per_double); + return (item32_t(real) << 16) | (item32_t(imag) << 0); +} + +/*********************************************************************** + * Convert items32 buffer to complex double + **********************************************************************/ +static const double doubles_per_short = double(1.0/shorts_per_double); + +static UHD_INLINE fc64_t item32_to_fc64(item32_t item){ + return fc64_t( + float(boost::int16_t(item >> 16)*doubles_per_short), + float(boost::int16_t(item >> 0)*doubles_per_short) + ); +} + #endif /* INCLUDED_LIBUHD_CONVERT_COMMON_HPP */ |