commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 03/28: basic: added int16 data types and fi


From: git
Subject: [Commit-gnuradio] [gnuradio] 03/28: basic: added int16 data types and filled in float32
Date: Mon, 15 Aug 2016 00:47:04 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

nwest pushed a commit to annotated tag gr_basic_work
in repository gnuradio.

commit d47b6530389a486e8737d34e1dca9ee73e9cdb96
Author: Josh Blum <address@hidden>
Date:   Tue Nov 8 15:55:05 2011 -0800

    basic: added int16 data types and filled in float32
---
 gr-basic/grc/gr_add_xx.xml      | 15 +++++++++
 gr-basic/include/gr_basic_add.h |  1 -
 gr-basic/lib/gr_basic_add.cc    | 69 +++++++++++++++++++++++++++++++----------
 3 files changed, 67 insertions(+), 18 deletions(-)

diff --git a/gr-basic/grc/gr_add_xx.xml b/gr-basic/grc/gr_add_xx.xml
index 320b6ce..5138294 100644
--- a/gr-basic/grc/gr_add_xx.xml
+++ b/gr-basic/grc/gr_add_xx.xml
@@ -19,6 +19,21 @@
                        <key>fc32</key>
                        <opt>enum:ADD_FC32</opt>
                </option>
+               <option>
+                       <name>F32</name>
+                       <key>f32</key>
+                       <opt>enum:ADD_F32</opt>
+               </option>
+               <option>
+                       <name>SC16</name>
+                       <key>sc16</key>
+                       <opt>enum:ADD_SC16</opt>
+               </option>
+               <option>
+                       <name>S16</name>
+                       <key>s16</key>
+                       <opt>enum:ADD_S16</opt>
+               </option>
        </param>
        <param>
                <name>Num Inputs</name>
diff --git a/gr-basic/include/gr_basic_add.h b/gr-basic/include/gr_basic_add.h
index 24a5f18..a1e5ef5 100644
--- a/gr-basic/include/gr_basic_add.h
+++ b/gr-basic/include/gr_basic_add.h
@@ -28,7 +28,6 @@ enum add_type{
     ADD_FC32,
     ADD_SC16,
     ADD_F32,
-    ADD_S32,
     ADD_S16,
 };
 
diff --git a/gr-basic/lib/gr_basic_add.cc b/gr-basic/lib/gr_basic_add.cc
index b9bb879..5415e9b 100644
--- a/gr-basic/lib/gr_basic_add.cc
+++ b/gr-basic/lib/gr_basic_add.cc
@@ -26,23 +26,58 @@
 #include <volk/volk.h>
 
 /***********************************************************************
- * Adder implementation with complex float 32
+ * Adder implementation with float32
  **********************************************************************/
-class gr_basic_add_fc32 : public basic_add{
+class gr_basic_add_f32 : public basic_add{
 public:
-    typedef std::complex<float> my_type;
+    gr_basic_add_f32(const size_t vlen):
+        gr_sync_block(
+            "add f32",
+            gr_make_io_signature (1, -1, sizeof(float)*vlen),
+            gr_make_io_signature (1, 1, sizeof(float)*vlen)
+        ),
+        _vlen(vlen)
+    {
+        const int alignment_multiple = volk_get_alignment() / 
(sizeof(float)*vlen);
+        set_output_multiple(std::max(1, alignment_multiple));
+    }
+
+    int work(
+        int noutput_items,
+        gr_vector_const_void_star &input_items,
+        gr_vector_void_star &output_items
+    ){
+        const size_t n_nums = noutput_items * _vlen;
+        float *out = reinterpret_cast<float *>(output_items[0]);
+        const float *in0 = reinterpret_cast<const float *>(input_items[0]);
+
+        for (size_t n = 1; n < input_items.size(); n++){
+            const float *in = reinterpret_cast<const float *>(input_items[n]);
+            volk_32f_x2_add_32f_a(out, in0, in, n_nums);
+            in0 = out; //for next input, we do output += input
+        }
 
-    gr_basic_add_fc32(const size_t vlen):
+        return noutput_items;
+    }
+
+private:
+    const size_t _vlen;
+};
+
+/***********************************************************************
+ * Adder implementation with int16
+ **********************************************************************/
+class gr_basic_add_s16 : public basic_add{
+public:
+    gr_basic_add_s16(const size_t vlen):
         gr_sync_block(
-            "add fc32",
-            gr_make_io_signature (1, -1, sizeof(my_type)*vlen),
-            gr_make_io_signature (1, 1, sizeof(my_type)*vlen)
+            "add s16",
+            gr_make_io_signature (1, -1, sizeof(uint16_t)*vlen),
+            gr_make_io_signature (1, 1, sizeof(uint16_t)*vlen)
         ),
         _vlen(vlen)
     {
-        int alignment_multiple = volk_get_alignment() / (sizeof(my_type)*vlen);
-        if(alignment_multiple < 1) alignment_multiple = 1;
-        set_output_multiple(alignment_multiple);
+        //TODO set output multiple to volk alignment
     }
 
     int work(
@@ -51,18 +86,15 @@ public:
         gr_vector_void_star &output_items
     ){
         const size_t n_nums = noutput_items * _vlen;
-        my_type *out = reinterpret_cast<my_type *>(output_items[0]);
-        const my_type *in0 = reinterpret_cast<const my_type *>(input_items[0]);
+        uint16_t *out = reinterpret_cast<uint16_t *>(output_items[0]);
+        const uint16_t *in0 = reinterpret_cast<const uint16_t 
*>(input_items[0]);
 
         for (size_t n = 1; n < input_items.size(); n++){
-            const my_type *in = reinterpret_cast<const my_type 
*>(input_items[n]);
+            const uint16_t *in = reinterpret_cast<const uint16_t 
*>(input_items[n]);
             //TODO - this is where you call into volk
-            volk_32f_x2_add_32f_a((float *)out, (float *)in0, (float *)in, 
n_nums*2);
-            /*
             for (size_t i = 0; i < n_nums; i++){
                 out[i] = in0[i] + in[i];
             }
-            */
             in0 = out; //for next input, we do output += input
         }
 
@@ -80,7 +112,10 @@ boost::shared_ptr<basic_add> basic_make_add(
     add_type type, const size_t vlen
 ){
     switch(type){
-    case ADD_FC32: return boost::shared_ptr<basic_add>(new 
gr_basic_add_fc32(vlen));
+    case ADD_FC32: return boost::shared_ptr<basic_add>(new 
gr_basic_add_f32(2*vlen));
+    case ADD_F32: return boost::shared_ptr<basic_add>(new 
gr_basic_add_f32(vlen));
+    case ADD_SC16: return boost::shared_ptr<basic_add>(new 
gr_basic_add_s16(2*vlen));
+    case ADD_S16: return boost::shared_ptr<basic_add>(new 
gr_basic_add_s16(vlen));
     default: throw std::invalid_argument("basic_make_add got unknown add 
type");
     }
 }



reply via email to

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