commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r9087 - in usrp2/branches/features/host-ng/host-ng: ap


From: eb
Subject: [Commit-gnuradio] r9087 - in usrp2/branches/features/host-ng/host-ng: apps lib
Date: Thu, 31 Jul 2008 18:47:04 -0600 (MDT)

Author: eb
Date: 2008-07-31 18:47:02 -0600 (Thu, 31 Jul 2008)
New Revision: 9087

Modified:
   usrp2/branches/features/host-ng/host-ng/apps/test2_usrp2.cc
   usrp2/branches/features/host-ng/host-ng/lib/copiers.cc
Log:
Merged eb/wip into features/host-ng.  Added floating point copy converters.


Modified: usrp2/branches/features/host-ng/host-ng/apps/test2_usrp2.cc
===================================================================
--- usrp2/branches/features/host-ng/host-ng/apps/test2_usrp2.cc 2008-07-31 
23:34:52 UTC (rev 9086)
+++ usrp2/branches/features/host-ng/host-ng/apps/test2_usrp2.cc 2008-08-01 
00:47:02 UTC (rev 9087)
@@ -368,8 +368,8 @@
   
   u2->stop_rx_streaming();
 
-  printf("\nCopy handler called %li times.\n", handler->nframes());
-  printf("Copy handler called with %li bytes.\n\n", 
handler->nsamples()*sizeof(uint32_t));
+  printf("\nCopy handler called %zd times.\n", handler->nframes());
+  printf("Copy handler called with %zd bytes.\n\n", 
handler->nsamples()*sizeof(uint32_t));
   printf("Elapsed time was %5.3f seconds.\n", elapsed);
   printf("Packet rate was %1.0f pkts/sec.\n", pps);
   printf("Approximate throughput was %5.2f MB/sec.\n", mbs);

Modified: usrp2/branches/features/host-ng/host-ng/lib/copiers.cc
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/copiers.cc      2008-07-31 
23:34:52 UTC (rev 9086)
+++ usrp2/branches/features/host-ng/host-ng/lib/copiers.cc      2008-08-01 
00:47:02 UTC (rev 9087)
@@ -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));
+    }
   }
 
 }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]