commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 15/28: basic: added super fast signal sourc


From: git
Subject: [Commit-gnuradio] [gnuradio] 15/28: basic: added super fast signal source
Date: Mon, 15 Aug 2016 00:47:06 +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 af4f41eb720758b0c2ccfad0380ff474b041f79e
Author: Josh Blum <address@hidden>
Date:   Thu Nov 10 12:27:55 2011 -0800

    basic: added super fast signal source
---
 gr-basic/grc/basic_block_tree.xml                  |   1 +
 gr-basic/grc/basic_sig_source.xml                  |  70 +++++++++
 gr-basic/include/CMakeLists.txt                    |   1 +
 gr-basic/include/gr_basic_sig_source.h             |  50 +++++++
 gr-basic/lib/CMakeLists.txt                        |   1 +
 gr-basic/lib/gr_basic_add.cc                       |   2 +-
 gr-basic/lib/gr_basic_add_const.cc                 |   2 +-
 gr-basic/lib/gr_basic_divide.cc                    |   2 +-
 gr-basic/lib/gr_basic_multiply.cc                  |   2 +-
 gr-basic/lib/gr_basic_multiply_const.cc            |   2 +-
 gr-basic/lib/gr_basic_sig_source.cc                | 164 +++++++++++++++++++++
 gr-basic/lib/gr_basic_subtract.cc                  |   2 +-
 gr-basic/swig/CMakeLists.txt                       |   1 +
 gr-basic/swig/{basic_swig.i => basic_sig_source.i} |  14 +-
 gr-basic/swig/basic_swig.i                         |   1 +
 15 files changed, 303 insertions(+), 12 deletions(-)

diff --git a/gr-basic/grc/basic_block_tree.xml 
b/gr-basic/grc/basic_block_tree.xml
index 3d5f83d..1e87971 100644
--- a/gr-basic/grc/basic_block_tree.xml
+++ b/gr-basic/grc/basic_block_tree.xml
@@ -30,6 +30,7 @@
     <name></name> <!-- Blank for Root Name -->
     <cat>
         <name>Basic</name>
+        <block>basic_sig_source</block>
         <block>basic_add</block>
         <block>basic_add_const</block>
         <block>basic_subtract</block>
diff --git a/gr-basic/grc/basic_sig_source.xml 
b/gr-basic/grc/basic_sig_source.xml
new file mode 100644
index 0000000..b7091c9
--- /dev/null
+++ b/gr-basic/grc/basic_sig_source.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0"?>
+<!--
+###################################################
+##Signal source block
+###################################################
+ -->
+<block>
+    <name>Signal Source</name>
+    <key>basic_sig_source</key>
+    <import>from gnuradio import basic</import>
+    <make>basic.sig_source(basic.OP_$($type().upper()))
+self.$(id).set_waveform($wave)
+self.$(id).set_offset($off)
+self.$(id).set_scaler($scaler)
+self.$(id).set_frequency($freq)</make>
+    <callback>set_waveform($wave)</callback>
+    <callback>set_offset($off)</callback>
+    <callback>set_scaleritude($scaler)</callback>
+    <callback>set_frequency($freq)</callback>
+    <param>
+        <name>Output Type</name>
+        <key>type</key>
+        <value>fc32</value>
+        <type>enum</type>
+        <option><name>FC64</name><key>fc64</key></option>
+        <option><name>F64</name><key>f64</key></option>
+        <option><name>FC32</name><key>fc32</key></option>
+        <option><name>F32</name><key>f32</key></option>
+        <option><name>SC64</name><key>sc64</key></option>
+        <option><name>S64</name><key>s64</key></option>
+        <option><name>SC32</name><key>sc32</key></option>
+        <option><name>S32</name><key>s32</key></option>
+        <option><name>SC16</name><key>sc16</key></option>
+        <option><name>S16</name><key>s16</key></option>
+        <option><name>SC8</name><key>sc8</key></option>
+        <option><name>S8</name><key>s8</key></option>
+    </param>
+    <param>
+        <name>Waveform</name>
+        <key>wave</key>
+        <value>COSINE</value>
+        <type>string</type>
+        <option><name>Constant</name><key>CONST</key></option>
+        <option><name>Cosine</name><key>COSINE</key></option>
+        <option><name>Ramp</name><key>RAMP</key></option>
+        <option><name>Square</name><key>SQUARE</key></option>
+    </param>
+    <param>
+        <name>Offset</name>
+        <key>off</key>
+        <value>0</value>
+        <type>complex</type>
+    </param>
+    <param>
+        <name>Scaler</name>
+        <key>scaler</key>
+        <value>1.0</value>
+        <type>complex</type>
+    </param>
+    <param>
+        <name>Frequency (frac)</name>
+        <key>freq</key>
+        <value>0.1</value>
+        <type>real</type>
+    </param>
+    <source>
+        <name>out</name>
+        <type>$type</type>
+    </source>
+</block>
diff --git a/gr-basic/include/CMakeLists.txt b/gr-basic/include/CMakeLists.txt
index cc503ed..2304d83 100644
--- a/gr-basic/include/CMakeLists.txt
+++ b/gr-basic/include/CMakeLists.txt
@@ -28,6 +28,7 @@ install(FILES
     gr_basic_multiply.h
     gr_basic_multiply_const.h
     gr_basic_op_types.h
+    gr_basic_sig_source.h
     gr_basic_subtract.h
     DESTINATION ${GR_INCLUDE_DIR}/gnuradio
     COMPONENT "basic_devel"
diff --git a/gr-basic/include/gr_basic_sig_source.h 
b/gr-basic/include/gr_basic_sig_source.h
new file mode 100644
index 0000000..a520aa8
--- /dev/null
+++ b/gr-basic/include/gr_basic_sig_source.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2011 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+#ifndef INCLUDED_GR_BASIC_SIG_SOURCE_H
+#define INCLUDED_GR_BASIC_SIG_SOURCE_H
+
+#include <gr_basic_api.h>
+#include <gr_sync_block.h>
+#include <gr_basic_op_types.h>
+#include <complex>
+
+class GR_BASIC_API gr_basic_sig_source : virtual public gr_sync_block{
+public:
+    typedef boost::shared_ptr<gr_basic_sig_source> sptr;
+
+    //! Make a new signal source given data type
+    static sptr make(op_type type);
+
+    //! Set the waveform type (CONST, COSINE, RAMP, SQUARE)
+    virtual void set_waveform(const std::string &) = 0;
+
+    //! Set the offset, this is a free addition operation
+    virtual void set_offset(const std::complex<double> &) = 0;
+
+    //! Set the scaler, this is a free multiply scalar operation
+    virtual void set_scaler(const std::complex<double> &) = 0;
+
+    //! Set the frequency, this is a fractional number between -1 and 1
+    virtual void set_frequency(const double) = 0;
+
+};
+
+#endif /* INCLUDED_GR_BASIC_SIG_SOURCE_H */
diff --git a/gr-basic/lib/CMakeLists.txt b/gr-basic/lib/CMakeLists.txt
index 3e03578..53e6c79 100644
--- a/gr-basic/lib/CMakeLists.txt
+++ b/gr-basic/lib/CMakeLists.txt
@@ -38,6 +38,7 @@ list(APPEND gr_basic_sources
     gr_basic_divide.cc
     gr_basic_multiply.cc
     gr_basic_multiply_const.cc
+    gr_basic_sig_source.cc
     gr_basic_subtract.cc
 )
 
diff --git a/gr-basic/lib/gr_basic_add.cc b/gr-basic/lib/gr_basic_add.cc
index 9451999..614e1d7 100644
--- a/gr-basic/lib/gr_basic_add.cc
+++ b/gr-basic/lib/gr_basic_add.cc
@@ -128,6 +128,6 @@ gr_basic_add::sptr gr_basic_add::make(op_type type, const 
size_t vlen){
     case OP_SC8: return sptr(new gr_basic_add_generic<int8_t>(2*vlen));
     case OP_S8: return sptr(new gr_basic_add_generic<int8_t>(vlen));
 
-    default: throw std::invalid_argument("basic_make_add got unknown add 
type");
+    default: throw std::invalid_argument("make add got unknown type");
     }
 }
diff --git a/gr-basic/lib/gr_basic_add_const.cc 
b/gr-basic/lib/gr_basic_add_const.cc
index cce5851..af305d8 100644
--- a/gr-basic/lib/gr_basic_add_const.cc
+++ b/gr-basic/lib/gr_basic_add_const.cc
@@ -114,6 +114,6 @@ gr_basic_add_const::sptr gr_basic_add_const::make(op_type 
type, const size_t vle
     case OP_SC8: return sptr(new 
gr_basic_add_const_generic<std::complex<int8_t> >(vlen));
     case OP_S8: return sptr(new gr_basic_add_const_generic<int8_t>(vlen));
 
-    default: throw std::invalid_argument("basic_make_add got unknown add 
type");
+    default: throw std::invalid_argument("make add const got unknown type");
     }
 }
diff --git a/gr-basic/lib/gr_basic_divide.cc b/gr-basic/lib/gr_basic_divide.cc
index d59795a..a3b1223 100644
--- a/gr-basic/lib/gr_basic_divide.cc
+++ b/gr-basic/lib/gr_basic_divide.cc
@@ -89,6 +89,6 @@ gr_basic_divide::sptr gr_basic_divide::make(op_type type, 
const size_t vlen){
     case OP_SC8: return sptr(new gr_basic_divide_generic<std::complex<int8_t> 
>(vlen));
     case OP_S8: return sptr(new gr_basic_divide_generic<int8_t>(vlen));
 
-    default: throw std::invalid_argument("basic_make_divide got unknown divide 
type");
+    default: throw std::invalid_argument("make divide got unknown type");
     }
 }
diff --git a/gr-basic/lib/gr_basic_multiply.cc 
b/gr-basic/lib/gr_basic_multiply.cc
index 185d3cb..770ee77 100644
--- a/gr-basic/lib/gr_basic_multiply.cc
+++ b/gr-basic/lib/gr_basic_multiply.cc
@@ -167,6 +167,6 @@ gr_basic_multiply::sptr gr_basic_multiply::make(op_type 
type, const size_t vlen)
     case OP_SC8: return sptr(new 
gr_basic_multiply_generic<std::complex<int8_t> >(vlen));
     case OP_S8: return sptr(new gr_basic_multiply_generic<int8_t>(vlen));
 
-    default: throw std::invalid_argument("basic_make_multiply got unknown 
multiply type");
+    default: throw std::invalid_argument("make multiply got unknown type");
     }
 }
diff --git a/gr-basic/lib/gr_basic_multiply_const.cc 
b/gr-basic/lib/gr_basic_multiply_const.cc
index a1b62f8..eb4a133 100644
--- a/gr-basic/lib/gr_basic_multiply_const.cc
+++ b/gr-basic/lib/gr_basic_multiply_const.cc
@@ -206,7 +206,7 @@ gr_basic_multiply_const::sptr 
gr_basic_multiply_const::make(op_type type, const
     case OP_SC8: return sptr(new 
gr_basic_multiply_const_generic<std::complex<int8_t> >(vlen));
     case OP_S8: return sptr(new gr_basic_multiply_const_generic<int8_t>(vlen));
 
-    default: throw std::invalid_argument("basic_make_multiply got unknown 
multiply type");
+    default: throw std::invalid_argument("make multiply const got unknown 
type");
     }
 }
 
diff --git a/gr-basic/lib/gr_basic_sig_source.cc 
b/gr-basic/lib/gr_basic_sig_source.cc
new file mode 100644
index 0000000..0d9ca49
--- /dev/null
+++ b/gr-basic/lib/gr_basic_sig_source.cc
@@ -0,0 +1,164 @@
+/*
+ * Copyright 2011 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <gr_basic_sig_source.h>
+#include <gr_io_signature.h>
+#include <stdexcept>
+#include <complex>
+#include <cmath>
+#include <boost/math/special_functions/round.hpp>
+
+static const size_t wave_table_size = 4096;
+
+/***********************************************************************
+ * Helper routines for conversion
+ **********************************************************************/
+template <typename type> void conv(const std::complex<double> &in, 
std::complex<type> &out){
+    out = std::complex<type>(in);
+}
+
+template <typename type> void conv(const std::complex<double> &in, type &out){
+    out = type(in.real());
+}
+
+/***********************************************************************
+ * Generic add const implementation
+ **********************************************************************/
+template <typename type>
+class gr_basic_sig_source_impl : public gr_basic_sig_source{
+public:
+    gr_basic_sig_source_impl(void):
+        gr_sync_block(
+            "signal source",
+            gr_make_io_signature (0, 0, 0),
+            gr_make_io_signature (1, 1, sizeof(type))
+        ),
+        _index(0), _step(0),
+        _table(wave_table_size),
+        _offset(0.0), _scaler(1.0),
+        _wave("CONST")
+    {
+        this->update_table();
+    }
+
+    int work(
+        int noutput_items,
+        gr_vector_const_void_star &input_items,
+        gr_vector_void_star &output_items
+    ){
+        type *out = reinterpret_cast<type *>(output_items[0]);
+        for (size_t i = 0; i < size_t(noutput_items); i++){
+            _index %= _table.size();
+            out[i] = _table[_index];
+            _index += _step;
+        }
+        return noutput_items;
+    }
+
+    void set_waveform(const std::string &wave){
+        _wave = wave;
+        this->update_table();
+    }
+
+    void set_offset(const std::complex<double> &offset){
+        _offset = offset;
+        this->update_table();
+    }
+
+    void set_scaler(const std::complex<double> &scaler){
+        _scaler = scaler;
+        this->update_table();
+    }
+
+    void set_frequency(const double freq){
+        _step = boost::math::iround(freq*_table.size());
+    }
+
+    void update_table(void){
+        if (_wave == "CONST"){
+            for (size_t i = 0; i < _table.size(); i++){
+                this->set_elem(i, 1.0);
+            }
+        }
+        else if (_wave == "COSINE"){
+            for (size_t i = 0; i < _table.size(); i++){
+                this->set_elem(i, std::pow(M_E, std::complex<double>(0, 
M_PI*2*i/_table.size())));
+            }
+        }
+        else if (_wave == "RAMP"){
+            for (size_t i = 0; i < _table.size(); i++){
+                const size_t q = (i+(3*_table.size())/4)%_table.size();
+                this->set_elem(i, std::complex<double>(
+                    2.0*i/(_table.size()-1) - 1.0,
+                    2.0*q/(_table.size()-1) - 1.0
+                ));
+            }
+        }
+        else if (_wave == "SQUARE"){
+            for (size_t i = 0; i < _table.size(); i++){
+                const size_t q = (i+(3*_table.size())/4)%_table.size();
+                this->set_elem(i, std::complex<double>(
+                    (i < _table.size()/2)? 0.0 : 1.0,
+                    (q < _table.size()/2)? 0.0 : 1.0
+                ));
+            }
+        }
+        else throw std::invalid_argument("sig source got unknown wave type: " 
+ _wave);
+    }
+
+    inline void set_elem(const size_t index, const std::complex<double> &val){
+        conv(_scaler * val + _offset, _table[index]);
+    }
+
+private:
+    size_t _index;
+    size_t _step;
+    std::vector<type> _table;
+    std::complex<double> _offset, _scaler;
+    std::string _wave;
+};
+
+/***********************************************************************
+ * Adder factory function
+ **********************************************************************/
+gr_basic_sig_source::sptr gr_basic_sig_source::make(op_type type){
+    switch(type){
+    case OP_FC64: return sptr(new 
gr_basic_sig_source_impl<std::complex<double> >());
+    case OP_F64: return sptr(new gr_basic_sig_source_impl<double>());
+
+    case OP_FC32: return sptr(new gr_basic_sig_source_impl<std::complex<float> 
>());
+    case OP_F32: return sptr(new gr_basic_sig_source_impl<float>());
+
+    case OP_SC64: return sptr(new 
gr_basic_sig_source_impl<std::complex<int64_t> >());
+    case OP_S64: return sptr(new gr_basic_sig_source_impl<int64_t>());
+
+    case OP_SC32: return sptr(new 
gr_basic_sig_source_impl<std::complex<int32_t> >());
+    case OP_S32: return sptr(new gr_basic_sig_source_impl<int32_t>());
+
+    case OP_SC16: return sptr(new 
gr_basic_sig_source_impl<std::complex<int16_t> >());
+    case OP_S16: return sptr(new gr_basic_sig_source_impl<int16_t>());
+
+    case OP_SC8: return sptr(new gr_basic_sig_source_impl<std::complex<int8_t> 
>());
+    case OP_S8: return sptr(new gr_basic_sig_source_impl<int8_t>());
+
+    default: throw std::invalid_argument("make sig source got unknown type");
+    }
+}
diff --git a/gr-basic/lib/gr_basic_subtract.cc 
b/gr-basic/lib/gr_basic_subtract.cc
index 1371431..df46716 100644
--- a/gr-basic/lib/gr_basic_subtract.cc
+++ b/gr-basic/lib/gr_basic_subtract.cc
@@ -89,6 +89,6 @@ gr_basic_subtract::sptr gr_basic_subtract::make(op_type type, 
const size_t vlen)
     case OP_SC8: return sptr(new gr_basic_subtract_generic<int8_t>(2*vlen));
     case OP_S8: return sptr(new gr_basic_subtract_generic<int8_t>(vlen));
 
-    default: throw std::invalid_argument("basic_make_subtract got unknown 
subtract type");
+    default: throw std::invalid_argument("make subtract got unknown type");
     }
 }
diff --git a/gr-basic/swig/CMakeLists.txt b/gr-basic/swig/CMakeLists.txt
index 7cb5cc0..c1ce280 100644
--- a/gr-basic/swig/CMakeLists.txt
+++ b/gr-basic/swig/CMakeLists.txt
@@ -41,6 +41,7 @@ GR_SWIG_INSTALL(
 install(
     FILES
     basic_swig.i
+    basic_sig_source.i
     basic_ops.i
     DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig
     COMPONENT "basic_swig"
diff --git a/gr-basic/swig/basic_swig.i b/gr-basic/swig/basic_sig_source.i
similarity index 88%
copy from gr-basic/swig/basic_swig.i
copy to gr-basic/swig/basic_sig_source.i
index 8bd5f42..83fe8b2 100644
--- a/gr-basic/swig/basic_swig.i
+++ b/gr-basic/swig/basic_sig_source.i
@@ -19,14 +19,16 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#define GR_BASIC_API
-
 ////////////////////////////////////////////////////////////////////////
-// standard includes
+// block headers
 ////////////////////////////////////////////////////////////////////////
-%include <gnuradio.i>
+%{
+#include <gr_basic_sig_source.h>
+%}
+
+%include <gr_basic_sig_source.h>
 
 ////////////////////////////////////////////////////////////////////////
-// block includes
+// block magic
 ////////////////////////////////////////////////////////////////////////
-%include <basic_ops.i>
+GR_SWIG_BLOCK_MAGIC2(gr_basic,sig_source)
diff --git a/gr-basic/swig/basic_swig.i b/gr-basic/swig/basic_swig.i
index 8bd5f42..6e94a22 100644
--- a/gr-basic/swig/basic_swig.i
+++ b/gr-basic/swig/basic_swig.i
@@ -30,3 +30,4 @@
 // block includes
 ////////////////////////////////////////////////////////////////////////
 %include <basic_ops.i>
+%include <basic_sig_source.i>



reply via email to

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