root / host / lib / convert / convert_common.hpp @ c0df7a31
History | View | Annotate | Download (4.97 KB)
| 1 |
//
|
|---|---|
| 2 |
// Copyright 2011 Ettus Research LLC
|
| 3 |
//
|
| 4 |
// This program is free software: you can redistribute it and/or modify
|
| 5 |
// it under the terms of the GNU General Public License as published by
|
| 6 |
// the Free Software Foundation, either version 3 of the License, or
|
| 7 |
// (at your option) any later version.
|
| 8 |
//
|
| 9 |
// This program is distributed in the hope that it will be useful,
|
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
// GNU General Public License for more details.
|
| 13 |
//
|
| 14 |
// You should have received a copy of the GNU General Public License
|
| 15 |
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
//
|
| 17 |
|
| 18 |
#ifndef INCLUDED_LIBUHD_CONVERT_COMMON_HPP
|
| 19 |
#define INCLUDED_LIBUHD_CONVERT_COMMON_HPP
|
| 20 |
|
| 21 |
#include <uhd/convert.hpp> |
| 22 |
#include <uhd/utils/static.hpp> |
| 23 |
#include <boost/cstdint.hpp> |
| 24 |
#include <complex> |
| 25 |
|
| 26 |
#define _DECLARE_CONVERTER(fcn, in_mark, num_in, out_mark, num_out, prio) \
|
| 27 |
static void fcn( \ |
| 28 |
const uhd::convert::input_type &inputs, \
|
| 29 |
const uhd::convert::output_type &outputs, \
|
| 30 |
const size_t nsamps, \
|
| 31 |
const double scale_factor \ |
| 32 |
); \ |
| 33 |
UHD_STATIC_BLOCK(__register_##fcn##_##prio){ \ |
| 34 |
uhd::convert::id_type id; \ |
| 35 |
id.input_markup = #in_mark; \
|
| 36 |
id.num_inputs = num_in; \ |
| 37 |
id.output_markup = #out_mark; \
|
| 38 |
id.num_outputs = num_out; \ |
| 39 |
uhd::convert::register_converter(id, fcn, prio); \ |
| 40 |
} \ |
| 41 |
static void fcn( \ |
| 42 |
const uhd::convert::input_type &inputs, \
|
| 43 |
const uhd::convert::output_type &outputs, \
|
| 44 |
const size_t nsamps, \
|
| 45 |
const double scale_factor \ |
| 46 |
) |
| 47 |
|
| 48 |
#define DECLARE_CONVERTER(in_mark, num_in, out_mark, num_out, prio) \
|
| 49 |
_DECLARE_CONVERTER(__convert_##in_mark##_##num_in##_##out_mark##_##num_out, in_mark, num_in, out_mark, num_out, prio) |
| 50 |
|
| 51 |
/***********************************************************************
|
| 52 |
* Typedefs
|
| 53 |
**********************************************************************/
|
| 54 |
typedef std::complex<double> fc64_t; |
| 55 |
typedef std::complex<float> fc32_t; |
| 56 |
typedef std::complex<boost::int32_t> sc32_t;
|
| 57 |
typedef std::complex<boost::int16_t> sc16_t;
|
| 58 |
typedef std::complex<boost::int8_t> sc8_t;
|
| 59 |
typedef double f64_t; |
| 60 |
typedef float f32_t; |
| 61 |
typedef boost::int32_t s32_t;
|
| 62 |
typedef boost::int16_t s16_t;
|
| 63 |
typedef boost::int8_t s8_t;
|
| 64 |
|
| 65 |
typedef boost::uint32_t item32_t;
|
| 66 |
|
| 67 |
/***********************************************************************
|
| 68 |
* Convert complex short buffer to items32
|
| 69 |
**********************************************************************/
|
| 70 |
static UHD_INLINE item32_t sc16_to_item32(sc16_t num, double){ |
| 71 |
boost::uint16_t real = num.real(); |
| 72 |
boost::uint16_t imag = num.imag(); |
| 73 |
return (item32_t(real) << 16) | (item32_t(imag) << 0); |
| 74 |
} |
| 75 |
|
| 76 |
/***********************************************************************
|
| 77 |
* Convert items32 buffer to complex short
|
| 78 |
**********************************************************************/
|
| 79 |
static UHD_INLINE sc16_t item32_to_sc16(item32_t item, double){ |
| 80 |
return sc16_t(
|
| 81 |
boost::int16_t(item >> 16),
|
| 82 |
boost::int16_t(item >> 0)
|
| 83 |
); |
| 84 |
} |
| 85 |
|
| 86 |
/***********************************************************************
|
| 87 |
* Convert complex float buffer to items32 (no swap)
|
| 88 |
**********************************************************************/
|
| 89 |
static UHD_INLINE item32_t fc32_to_item32(fc32_t num, double scale_factor){ |
| 90 |
boost::uint16_t real = boost::int16_t(num.real()*float(scale_factor));
|
| 91 |
boost::uint16_t imag = boost::int16_t(num.imag()*float(scale_factor));
|
| 92 |
return (item32_t(real) << 16) | (item32_t(imag) << 0); |
| 93 |
} |
| 94 |
|
| 95 |
/***********************************************************************
|
| 96 |
* Convert items32 buffer to complex float
|
| 97 |
**********************************************************************/
|
| 98 |
static UHD_INLINE fc32_t item32_to_fc32(item32_t item, double scale_factor){ |
| 99 |
return fc32_t(
|
| 100 |
float(boost::int16_t(item >> 16)*float(scale_factor)), |
| 101 |
float(boost::int16_t(item >> 0)*float(scale_factor)) |
| 102 |
); |
| 103 |
} |
| 104 |
|
| 105 |
/***********************************************************************
|
| 106 |
* Convert complex double buffer to items32 (no swap)
|
| 107 |
**********************************************************************/
|
| 108 |
static UHD_INLINE item32_t fc64_to_item32(fc64_t num, double scale_factor){ |
| 109 |
boost::uint16_t real = boost::int16_t(num.real()*scale_factor); |
| 110 |
boost::uint16_t imag = boost::int16_t(num.imag()*scale_factor); |
| 111 |
return (item32_t(real) << 16) | (item32_t(imag) << 0); |
| 112 |
} |
| 113 |
|
| 114 |
/***********************************************************************
|
| 115 |
* Convert items32 buffer to complex double
|
| 116 |
**********************************************************************/
|
| 117 |
static UHD_INLINE fc64_t item32_to_fc64(item32_t item, double scale_factor){ |
| 118 |
return fc64_t(
|
| 119 |
float(boost::int16_t(item >> 16)*scale_factor), |
| 120 |
float(boost::int16_t(item >> 0)*scale_factor) |
| 121 |
); |
| 122 |
} |
| 123 |
|
| 124 |
#endif /* INCLUDED_LIBUHD_CONVERT_COMMON_HPP */ |