[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r9080 - usrp2/branches/developers/eb/u2-wip/host-ng/li
From: |
eb |
Subject: |
[Commit-gnuradio] r9080 - usrp2/branches/developers/eb/u2-wip/host-ng/lib |
Date: |
Wed, 30 Jul 2008 21:17:27 -0600 (MDT) |
Author: eb
Date: 2008-07-30 21:17:26 -0600 (Wed, 30 Jul 2008)
New Revision: 9080
Modified:
usrp2/branches/developers/eb/u2-wip/host-ng/lib/copiers.cc
Log:
added I&Q conversions to/from complex<float>
Modified: usrp2/branches/developers/eb/u2-wip/host-ng/lib/copiers.cc
===================================================================
--- usrp2/branches/developers/eb/u2-wip/host-ng/lib/copiers.cc 2008-07-31
02:52:49 UTC (rev 9079)
+++ usrp2/branches/developers/eb/u2-wip/host-ng/lib/copiers.cc 2008-07-31
03:17:26 UTC (rev 9080)
@@ -24,6 +24,8 @@
#endif
#include <usrp2/copiers.h>
#include <gruel/inet.h>
+#include <gr_math.h>
+#include <math.h>
#include <stdexcept>
#include <assert.h>
#include <string.h>
@@ -33,6 +35,11 @@
namespace usrp2 {
/*
+ * N.B., in all of these, uint32_t *items is NOT 32-bit aligned!
+ * FIXME Needs fix for non-x86 machines.
+ */
+
+ /*
* ----------------------------------------------------------------
* Copy and convert from USRP2 wire format to host format
* ----------------------------------------------------------------
@@ -61,15 +68,22 @@
}
+ /*
+ * endian swap if required and map [-32768, 32767] -> [1.0, +1.0)
+ */
void
copy_u2_complex_16_to_host_complex_float(size_t nitems,
const uint32_t *items,
std::complex<float> *host_items)
{
- throw std::runtime_error("not implemented");
+ for (size_t i = 0; i < nitems; i++){
+ uint32_t t = ntohx(items[i]);
+ int16_t re = (t >> 16) & 0xffff;
+ int16_t im = (t & 0xffff);
+ host_items[i] = std::complex<float>(re * 1.0/32768, im * 1.0/32768);
+ }
}
-
/*
* ----------------------------------------------------------------
* Copy and convert from host format to USRP2 wire format
@@ -97,12 +111,23 @@
}
+ static inline int16_t
+ clip_and_scale(float x)
+ {
+ return static_cast<int16_t>(rintf(gr_branchless_clip(x, 1.0) * 32767.0));
+ }
+
void
copy_host_complex_float_to_u2_complex_16(size_t nitems,
const std::complex<float>
*host_items,
uint32_t *items)
{
- throw std::runtime_error("not implemented");
+ for (size_t i = 0; i < nitems; i++){
+ int16_t re = clip_and_scale(host_items[i].real());
+ int16_t im = clip_and_scale(host_items[i].imag());
+
+ items[i] = htonl((re << 16) | (im & 0xffff));
+ }
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r9080 - usrp2/branches/developers/eb/u2-wip/host-ng/lib,
eb <=