summaryrefslogtreecommitdiff
path: root/gr-analog/lib
diff options
context:
space:
mode:
authorAndrej Rode <mail@andrejro.de>2018-08-19 21:17:28 +0200
committerAndrej Rode <mail@andrejro.de>2018-08-25 20:21:23 +0200
commitaa844b050d5b658ab8d6961a3678251b65db7ce7 (patch)
treedd666d408aff9d77f0fa72c6913d0fbc4d0a1445 /gr-analog/lib
parent107513f6d4aaaa6515217c25c7226154f53aed41 (diff)
analog: replace gengen with C++ templates
Diffstat (limited to 'gr-analog/lib')
-rw-r--r--gr-analog/lib/CMakeLists.txt17
-rw-r--r--gr-analog/lib/fastnoise_source_X_impl.cc.t175
-rw-r--r--gr-analog/lib/fastnoise_source_impl.cc191
-rw-r--r--gr-analog/lib/fastnoise_source_impl.h (renamed from gr-analog/lib/fastnoise_source_X_impl.h.t)22
-rw-r--r--gr-analog/lib/noise_source_X_impl.cc.t139
-rw-r--r--gr-analog/lib/noise_source_impl.cc150
-rw-r--r--gr-analog/lib/noise_source_impl.h (renamed from gr-analog/lib/noise_source_X_impl.h.t)16
-rw-r--r--gr-analog/lib/random_uniform_source_X_impl.cc.t83
-rw-r--r--gr-analog/lib/random_uniform_source_impl.cc76
-rw-r--r--gr-analog/lib/random_uniform_source_impl.h (renamed from gr-analog/lib/random_uniform_source_X_impl.h.t)16
-rw-r--r--gr-analog/lib/sig_source_X_impl.cc.t287
-rw-r--r--gr-analog/lib/sig_source_impl.cc287
-rw-r--r--gr-analog/lib/sig_source_impl.h (renamed from gr-analog/lib/sig_source_X_impl.h.t)26
13 files changed, 749 insertions, 736 deletions
diff --git a/gr-analog/lib/CMakeLists.txt b/gr-analog/lib/CMakeLists.txt
index a3b279f900..eeb287db05 100644
--- a/gr-analog/lib/CMakeLists.txt
+++ b/gr-analog/lib/CMakeLists.txt
@@ -40,19 +40,9 @@ if(ENABLE_GR_CTRLPORT)
endif(ENABLE_GR_CTRLPORT)
########################################################################
-# Invoke macro to generate various sources and headers
-########################################################################
-include(GrMiscUtils)
-GR_EXPAND_X_CC_H(analog noise_source_X_impl s i f c)
-GR_EXPAND_X_CC_H(analog fastnoise_source_X_impl s i f c)
-GR_EXPAND_X_CC_H(analog sig_source_X_impl s i f c)
-GR_EXPAND_X_CC_H(analog random_uniform_source_X_impl b s i)
-
-########################################################################
# Setup library
########################################################################
list(APPEND analog_sources
- ${generated_sources}
cpm.cc
squelch_base_cc_impl.cc
squelch_base_ff_impl.cc
@@ -64,9 +54,11 @@ list(APPEND analog_sources
cpfsk_bc_impl.cc
ctcss_squelch_ff_impl.cc
dpll_bb_impl.cc
+ fastnoise_source_impl.cc
feedforward_agc_cc_impl.cc
fmdet_cf_impl.cc
frequency_modulator_fc_impl.cc
+ noise_source_impl.cc
phase_modulator_fc_impl.cc
pll_carriertracking_cc_impl.cc
pll_freqdet_cf_impl.cc
@@ -78,6 +70,8 @@ list(APPEND analog_sources
pwr_squelch_ff_impl.cc
quadrature_demod_cf_impl.cc
rail_ff_impl.cc
+ random_uniform_source_impl.cc
+ sig_source_impl.cc
simple_squelch_cc_impl.cc
)
@@ -107,13 +101,12 @@ list(APPEND analog_libs
add_library(gnuradio-analog SHARED ${analog_sources})
target_link_libraries(gnuradio-analog ${analog_libs})
GR_LIBRARY_FOO(gnuradio-analog)
-add_dependencies(gnuradio-analog analog_generated_includes analog_generated_swigs gnuradio-filter)
+add_dependencies(gnuradio-analog analog_generated_swigs gnuradio-filter)
if(ENABLE_STATIC_LIBS)
add_library(gnuradio-analog_static STATIC ${analog_sources})
add_dependencies(gnuradio-analog_static
- analog_generated_includes
gnuradio-filter_static)
if(NOT WIN32)
diff --git a/gr-analog/lib/fastnoise_source_X_impl.cc.t b/gr-analog/lib/fastnoise_source_X_impl.cc.t
deleted file mode 100644
index 940918b11b..0000000000
--- a/gr-analog/lib/fastnoise_source_X_impl.cc.t
+++ /dev/null
@@ -1,175 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2013 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.
- */
-
-/* @WARNING@ */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "@IMPL_NAME@.h"
-#include <gnuradio/io_signature.h>
-#include <stdexcept>
-
-namespace gr {
- namespace analog {
-
- @BASE_NAME@::sptr
- @BASE_NAME@::make(noise_type_t type, float ampl, long seed, long samples)
- {
- return gnuradio::get_initial_sptr
- (new @IMPL_NAME@(type, ampl, seed, samples));
- }
-
- @IMPL_NAME@::@IMPL_NAME@(noise_type_t type, float ampl, long seed, long samples)
- : sync_block("@BASE_NAME@",
- io_signature::make(0, 0, 0),
- io_signature::make(1, 1, sizeof(@TYPE@))),
- d_type(type),
-#if @IS_COMPLEX@ // complex?
- d_ampl(ampl/sqrtf(2.0f)),
-#else
- d_ampl(ampl),
-#endif
- d_rng(seed)
- {
- d_samples.resize(samples);
- generate();
- }
-
- @IMPL_NAME@::~@IMPL_NAME@()
- {
- }
-
- void
- @IMPL_NAME@::set_type(noise_type_t type)
- {
- gr::thread::scoped_lock l(d_setlock);
- d_type = type;
- generate();
- }
-
- void
- @IMPL_NAME@::set_amplitude(float ampl)
- {
- gr::thread::scoped_lock l(d_setlock);
-#if @IS_COMPLEX@ // complex?
- d_ampl = ampl/sqrtf(2.0f);
-#else
- d_ampl = ampl;
-#endif
- generate();
- }
-
- void
- @IMPL_NAME@::generate()
- {
- int noutput_items = d_samples.size();
- switch(d_type){
-#if @IS_COMPLEX@ // complex?
-
- case GR_UNIFORM:
- for(int i = 0; i < noutput_items; i++)
- d_samples[i] = gr_complex(d_ampl * ((d_rng.ran1() * 2.0) - 1.0),
- d_ampl * ((d_rng.ran1() * 2.0) - 1.0));
- break;
-
- case GR_GAUSSIAN:
- for(int i = 0; i < noutput_items; i++)
- d_samples[i] = d_ampl * d_rng.rayleigh_complex();
- break;
-
-#else // nope...
-
- case GR_UNIFORM:
- for(int i = 0; i < noutput_items; i++)
- d_samples[i] = (@TYPE@)(d_ampl * ((d_rng.ran1() * 2.0) - 1.0));
- break;
-
- case GR_GAUSSIAN:
- for(int i = 0; i < noutput_items; i++)
- d_samples[i] = (@TYPE@)(d_ampl * d_rng.gasdev());
- break;
-
- case GR_LAPLACIAN:
- for(int i = 0; i < noutput_items; i++)
- d_samples[i] = (@TYPE@)(d_ampl * d_rng.laplacian());
- break;
-
- case GR_IMPULSE: // FIXME changeable impulse settings
- for(int i = 0; i < noutput_items; i++)
- d_samples[i] = (@TYPE@)(d_ampl * d_rng.impulse(9));
- break;
-#endif
-
- default:
- throw std::runtime_error("invalid type");
- }
- }
-
- int
- @IMPL_NAME@::work(int noutput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items)
- {
- gr::thread::scoped_lock l(d_setlock);
-
- @TYPE@ *out = (@TYPE@*)output_items[0];
-
- for(int i=0; i<noutput_items; i++) {
- out[i] = sample();
- }
-
- return noutput_items;
- }
-
- @TYPE@ @IMPL_NAME@::sample()
- {
-#ifdef HAVE_RAND48
- size_t idx = lrand48() % d_samples.size();
-#else
- size_t idx = rand() % d_samples.size();
-#endif
- return d_samples[idx];
- }
-
-#ifndef FASTNOISE_RANDOM_SIGN
-#ifndef HAVE_RAND48
-#define FASTNOISE_RANDOM_SIGN ((rand()%2==0)?1:-1)
-#else
-#define FASTNOISE_RANDOM_SIGN ((lrand48()%2==0)?1:-1)
-#endif
-#endif
-
- @TYPE@ @IMPL_NAME@::sample_unbiased()
- {
-#if @IS_COMPLEX@
- gr_complex s(sample());
- return gr_complex(FASTNOISE_RANDOM_SIGN * s.real(),
- FASTNOISE_RANDOM_SIGN * s.imag());
-#else
- return FASTNOISE_RANDOM_SIGN * sample();
-#endif
- }
-
- } /* namespace analog */
-} /* namespace gr */
diff --git a/gr-analog/lib/fastnoise_source_impl.cc b/gr-analog/lib/fastnoise_source_impl.cc
new file mode 100644
index 0000000000..ef85586b98
--- /dev/null
+++ b/gr-analog/lib/fastnoise_source_impl.cc
@@ -0,0 +1,191 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2013,2018 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.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "fastnoise_source_impl.h"
+#include <gnuradio/io_signature.h>
+#include <stdexcept>
+
+namespace gr {
+namespace analog {
+
+template <class T>
+typename fastnoise_source<T>::sptr
+fastnoise_source<T>::make(noise_type_t type, float ampl, long seed, long samples) {
+ return gnuradio::get_initial_sptr(new fastnoise_source_impl<T>(type, ampl, seed, samples));
+}
+
+ template <>
+ void fastnoise_source_impl<gr_complex>::generate() {
+ int noutput_items = d_samples.size();
+ switch (d_type) {
+ case GR_UNIFORM:
+ for (int i = 0; i < noutput_items; i++)
+ d_samples[i] = gr_complex(d_ampl * ((d_rng.ran1() * 2.0) - 1.0),
+ d_ampl * ((d_rng.ran1() * 2.0) - 1.0));
+ break;
+
+ case GR_GAUSSIAN:
+ for (int i = 0; i < noutput_items; i++)
+ d_samples[i] = d_ampl * d_rng.rayleigh_complex();
+ break;
+ default:
+ throw std::runtime_error("invalid type");
+ }
+ }
+
+template <class T>
+fastnoise_source_impl<T>::fastnoise_source_impl(noise_type_t type,
+ float ampl,
+ long seed,
+ long samples)
+ : sync_block(
+ "fastnoise_source", io_signature::make(0, 0, 0), io_signature::make(1, 1, sizeof(T))),
+ d_type(type), d_ampl(ampl), d_rng(seed) {
+ d_samples.resize(samples);
+ generate();
+}
+
+
+template <>
+fastnoise_source_impl<gr_complex>::fastnoise_source_impl(noise_type_t type,
+ float ampl,
+ long seed,
+ long samples)
+ : sync_block("fastnoise_source",
+ io_signature::make(0, 0, 0),
+ io_signature::make(1, 1, sizeof(gr_complex))),
+ d_type(type), d_ampl(ampl / sqrtf(2.0f)), d_rng(seed) {
+ d_samples.resize(samples);
+ generate();
+}
+
+template <class T>
+fastnoise_source_impl<T>::~fastnoise_source_impl() {}
+
+template <class T>
+void fastnoise_source_impl<T>::set_type(noise_type_t type) {
+ gr::thread::scoped_lock l(this->d_setlock);
+ d_type = type;
+ generate();
+}
+
+template <class T>
+void fastnoise_source_impl<T>::set_amplitude(float ampl) {
+ gr::thread::scoped_lock l(this->d_setlock);
+ d_ampl = ampl;
+ generate();
+}
+
+template <>
+void fastnoise_source_impl<gr_complex>::set_amplitude(float ampl) {
+ gr::thread::scoped_lock l(this->d_setlock);
+ d_ampl = ampl / sqrtf(2.0f);
+ generate();
+}
+
+
+template <class T>
+void fastnoise_source_impl<T>::generate() {
+ int noutput_items = d_samples.size();
+ switch (d_type) {
+ case GR_UNIFORM:
+ for (int i = 0; i < noutput_items; i++)
+ d_samples[i] = (T)(d_ampl * ((d_rng.ran1() * 2.0) - 1.0));
+ break;
+
+ case GR_GAUSSIAN:
+ for (int i = 0; i < noutput_items; i++)
+ d_samples[i] = (T)(d_ampl * d_rng.gasdev());
+ break;
+
+ case GR_LAPLACIAN:
+ for (int i = 0; i < noutput_items; i++)
+ d_samples[i] = (T)(d_ampl * d_rng.laplacian());
+ break;
+
+ case GR_IMPULSE: // FIXME changeable impulse settings
+ for (int i = 0; i < noutput_items; i++)
+ d_samples[i] = (T)(d_ampl * d_rng.impulse(9));
+ break;
+ default:
+ throw std::runtime_error("invalid type");
+ }
+}
+
+
+
+template <class T>
+int fastnoise_source_impl<T>::work(int noutput_items,
+ gr_vector_const_void_star& input_items,
+ gr_vector_void_star& output_items) {
+ gr::thread::scoped_lock l(this->d_setlock);
+
+ T* out = (T*)output_items[0];
+
+ for (int i = 0; i < noutput_items; i++) {
+ out[i] = sample();
+ }
+
+ return noutput_items;
+}
+
+template <class T>
+T fastnoise_source_impl<T>::sample() {
+#ifdef HAVE_RAND48
+ size_t idx = lrand48() % d_samples.size();
+#else
+ size_t idx = rand() % d_samples.size();
+#endif
+ return d_samples[idx];
+}
+
+#ifndef FASTNOISE_RANDOM_SIGN
+#ifndef HAVE_RAND48
+#define FASTNOISE_RANDOM_SIGN ((rand() % 2 == 0) ? 1 : -1)
+#else
+#define FASTNOISE_RANDOM_SIGN ((lrand48() % 2 == 0) ? 1 : -1)
+#endif
+#endif
+
+template <class T>
+T fastnoise_source_impl<T>::sample_unbiased() {
+ return FASTNOISE_RANDOM_SIGN * sample();
+}
+
+template <>
+gr_complex fastnoise_source_impl<gr_complex>::sample_unbiased() {
+ gr_complex s(sample());
+ return gr_complex(FASTNOISE_RANDOM_SIGN * s.real(), FASTNOISE_RANDOM_SIGN * s.imag());
+}
+
+
+template class fastnoise_source<std::int16_t>;
+template class fastnoise_source<std::int32_t>;
+template class fastnoise_source<float>;
+template class fastnoise_source<gr_complex>;
+} /* namespace analog */
+} /* namespace gr */
diff --git a/gr-analog/lib/fastnoise_source_X_impl.h.t b/gr-analog/lib/fastnoise_source_impl.h
index 8ad1e4f8fe..2795b269dc 100644
--- a/gr-analog/lib/fastnoise_source_X_impl.h.t
+++ b/gr-analog/lib/fastnoise_source_impl.h
@@ -20,31 +20,31 @@
* Boston, MA 02110-1301, USA.
*/
-// @WARNING@
-#ifndef @GUARD_NAME@
-#define @GUARD_NAME@
+#ifndef FASTNOISE_SOURCE_IMPL_H
+#define FASTNOISE_SOURCE_IMPL_H
-#include <gnuradio/analog/@BASE_NAME@.h>
+#include <gnuradio/analog/fastnoise_source.h>
#include <gnuradio/random.h>
namespace gr {
namespace analog {
- class @IMPL_NAME@ : public @BASE_NAME@
+template<class T>
+ class fastnoise_source_impl : public fastnoise_source<T>
{
private:
noise_type_t d_type;
float d_ampl;
gr::random d_rng;
- std::vector<@TYPE@> d_samples;
+ std::vector<T> d_samples;
public:
- @IMPL_NAME@(noise_type_t type, float ampl, long seed, long samples);
- ~@IMPL_NAME@();
+ fastnoise_source_impl(noise_type_t type, float ampl, long seed, long samples);
+ ~fastnoise_source_impl();
- @TYPE@ sample();
- @TYPE@ sample_unbiased();
+ T sample();
+ T sample_unbiased();
void set_type(noise_type_t type);
void set_amplitude(float ampl);
@@ -61,4 +61,4 @@ namespace gr {
} /* namespace filter */
} /* namespace gr */
-#endif /* @GUARD_NAME@ */
+#endif /* FASTNOISE_SOURCE_IMPL_H */
diff --git a/gr-analog/lib/noise_source_X_impl.cc.t b/gr-analog/lib/noise_source_X_impl.cc.t
deleted file mode 100644
index d8c1b7eb1b..0000000000
--- a/gr-analog/lib/noise_source_X_impl.cc.t
+++ /dev/null
@@ -1,139 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2004,2010,2012 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.
- */
-
-/* @WARNING@ */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "@IMPL_NAME@.h"
-#include <gnuradio/io_signature.h>
-#include <stdexcept>
-
-namespace gr {
- namespace analog {
-
- @BASE_NAME@::sptr
- @BASE_NAME@::make(noise_type_t type, float ampl, long seed)
- {
- return gnuradio::get_initial_sptr
- (new @IMPL_NAME@(type, ampl, seed));
- }
-
- @IMPL_NAME@::@IMPL_NAME@(noise_type_t type, float ampl, long seed)
- : sync_block("@BASE_NAME@",
- io_signature::make(0, 0, 0),
- io_signature::make(1, 1, sizeof(@TYPE@))),
- d_type(type),
-#if @IS_COMPLEX@ // complex?
- d_ampl(ampl/sqrtf(2.0f)),
-#else
- d_ampl(ampl),
-#endif
- d_rng(seed)
- {
- }
-
- @IMPL_NAME@::~@IMPL_NAME@()
- {
- }
-
- void
- @IMPL_NAME@::set_type(noise_type_t type)
- {
- gr::thread::scoped_lock l(d_setlock);
- d_type = type;
- }
-
- void
- @IMPL_NAME@::set_amplitude(float ampl)
- {
- gr::thread::scoped_lock l(d_setlock);
-#if @IS_COMPLEX@ // complex?
- d_ampl = ampl/sqrtf(2.0f);
-#else
- d_ampl = ampl;
-#endif
- }
-
- int
- @IMPL_NAME@::work(int noutput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items)
- {
- gr::thread::scoped_lock l(d_setlock);
-
- @TYPE@ *out = (@TYPE@*)output_items[0];
-
- switch(d_type) {
-#if @IS_COMPLEX@ // complex?
-
- case GR_UNIFORM:
- for(int i = 0; i < noutput_items; i++) {
- out[i] = gr_complex(d_ampl * ((d_rng.ran1() * 2.0) - 1.0),
- d_ampl * ((d_rng.ran1() * 2.0) - 1.0));
- }
- break;
-
- case GR_GAUSSIAN:
- for(int i = 0; i < noutput_items; i++) {
- out[i] = d_ampl * d_rng.rayleigh_complex();
- }
- break;
-
-#else // nope...
-
- case GR_UNIFORM:
- for(int i = 0; i < noutput_items; i++) {
- out[i] = (@TYPE@)(d_ampl * ((d_rng.ran1() * 2.0) - 1.0));
- }
- break;
-
- case GR_GAUSSIAN:
- for(int i = 0; i < noutput_items; i++) {
- out[i] = (@TYPE@)(d_ampl * d_rng.gasdev());
- }
- break;
-
- case GR_LAPLACIAN:
- for(int i = 0; i < noutput_items; i++) {
- out[i] = (@TYPE@)(d_ampl * d_rng.laplacian());
- }
- break;
-
- case GR_IMPULSE: // FIXME changeable impulse settings
- for(int i = 0; i < noutput_items; i++) {
- out[i] = (@TYPE@)(d_ampl * d_rng.impulse(9));
- }
- break;
-#endif
-
- default:
- throw std::runtime_error("invalid type");
- }
-
- return noutput_items;
- }
-
- } /* namespace analog */
-} /* namespace gr */
diff --git a/gr-analog/lib/noise_source_impl.cc b/gr-analog/lib/noise_source_impl.cc
new file mode 100644
index 0000000000..a3dd2c20c9
--- /dev/null
+++ b/gr-analog/lib/noise_source_impl.cc
@@ -0,0 +1,150 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2010,2012,2018 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.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "noise_source_impl.h"
+#include <gnuradio/io_signature.h>
+#include <stdexcept>
+
+namespace gr {
+namespace analog {
+
+template <class T>
+typename noise_source<T>::sptr noise_source<T>::make(noise_type_t type, float ampl, long seed) {
+ return gnuradio::get_initial_sptr(new noise_source_impl<T>(type, ampl, seed));
+}
+
+template <class T>
+noise_source_impl<T>::noise_source_impl(noise_type_t type, float ampl, long seed)
+ : sync_block("noise_source", io_signature::make(0, 0, 0), io_signature::make(1, 1, sizeof(T))),
+ d_type(type), d_ampl(ampl), d_rng(seed) {}
+
+template <>
+noise_source_impl<gr_complex>::noise_source_impl(noise_type_t type, float ampl, long seed)
+ : sync_block("noise_source",
+ io_signature::make(0, 0, 0),
+ io_signature::make(1, 1, sizeof(gr_complex))),
+ d_type(type), d_ampl(ampl / sqrtf(2.0f)), d_rng(seed) {}
+
+
+template <class T>
+noise_source_impl<T>::~noise_source_impl<T>() {}
+
+template <class T>
+void noise_source_impl<T>::set_type(noise_type_t type) {
+ gr::thread::scoped_lock l(this->d_setlock);
+ d_type = type;
+}
+
+template <class T>
+void noise_source_impl<T>::set_amplitude(float ampl) {
+ gr::thread::scoped_lock l(this->d_setlock);
+ d_ampl = ampl;
+}
+
+template <>
+void noise_source_impl<gr_complex>::set_amplitude(float ampl) {
+ gr::thread::scoped_lock l(this->d_setlock);
+ d_ampl = ampl / sqrtf(2.0f);
+}
+
+
+template <class T>
+int noise_source_impl<T>::work(int noutput_items,
+ gr_vector_const_void_star& input_items,
+ gr_vector_void_star& output_items) {
+ gr::thread::scoped_lock l(this->d_setlock);
+
+ T* out = (T*)output_items[0];
+
+ switch (d_type) {
+ case GR_UNIFORM:
+ for (int i = 0; i < noutput_items; i++) {
+ out[i] = (T)(d_ampl * ((d_rng.ran1() * 2.0) - 1.0));
+ }
+ break;
+
+ case GR_GAUSSIAN:
+ for (int i = 0; i < noutput_items; i++) {
+ out[i] = (T)(d_ampl * d_rng.gasdev());
+ }
+ break;
+
+ case GR_LAPLACIAN:
+ for (int i = 0; i < noutput_items; i++) {
+ out[i] = (T)(d_ampl * d_rng.laplacian());
+ }
+ break;
+
+ case GR_IMPULSE: // FIXME changeable impulse settings
+ for (int i = 0; i < noutput_items; i++) {
+ out[i] = (T)(d_ampl * d_rng.impulse(9));
+ }
+ break;
+ default:
+ throw std::runtime_error("invalid type");
+ }
+
+ return noutput_items;
+}
+
+template <>
+int noise_source_impl<gr_complex>::work(int noutput_items,
+ gr_vector_const_void_star& input_items,
+ gr_vector_void_star& output_items) {
+ gr::thread::scoped_lock l(this->d_setlock);
+
+ gr_complex* out = (gr_complex*)output_items[0];
+
+ switch (d_type) {
+
+ case GR_UNIFORM:
+ for (int i = 0; i < noutput_items; i++) {
+ out[i] = gr_complex(d_ampl * ((d_rng.ran1() * 2.0) - 1.0),
+ d_ampl * ((d_rng.ran1() * 2.0) - 1.0));
+ }
+ break;
+
+ case GR_GAUSSIAN:
+ for (int i = 0; i < noutput_items; i++) {
+ out[i] = d_ampl * d_rng.rayleigh_complex();
+ }
+ break;
+
+ default:
+ throw std::runtime_error("invalid type");
+ }
+
+ return noutput_items;
+}
+
+
+template class noise_source<std::int16_t>;
+template class noise_source<std::int32_t>;
+template class noise_source<float>;
+template class noise_source<gr_complex>;
+} /* namespace analog */
+} /* namespace gr */
diff --git a/gr-analog/lib/noise_source_X_impl.h.t b/gr-analog/lib/noise_source_impl.h
index cd7a3e1636..ddef4f25e9 100644
--- a/gr-analog/lib/noise_source_X_impl.h.t
+++ b/gr-analog/lib/noise_source_impl.h
@@ -20,26 +20,26 @@
* Boston, MA 02110-1301, USA.
*/
-/* @WARNING@ */
-#ifndef @GUARD_NAME@
-#define @GUARD_NAME@
+#ifndef NOISE_SOURCE_IMPL_H
+#define NOISE_SOURCE_IMPL_H
-#include <gnuradio/analog/@BASE_NAME@.h>
+#include <gnuradio/analog/noise_source.h>
#include <gnuradio/random.h>
namespace gr {
namespace analog {
- class @IMPL_NAME@ : public @BASE_NAME@
+template<class T>
+ class noise_source_impl : public noise_source<T>
{
noise_type_t d_type;
float d_ampl;
gr::random d_rng;
public:
- @IMPL_NAME@(noise_type_t type, float ampl, long seed = 0);
- ~@IMPL_NAME@();
+ noise_source_impl(noise_type_t type, float ampl, long seed = 0);
+ ~noise_source_impl();
void set_type(noise_type_t type);
void set_amplitude(float ampl);
@@ -55,4 +55,4 @@ namespace gr {
} /* namespace filter */
} /* namespace gr */
-#endif /* @GUARD_NAME@ */
+#endif /* NOISE_SOURCE_IMPL_H */
diff --git a/gr-analog/lib/random_uniform_source_X_impl.cc.t b/gr-analog/lib/random_uniform_source_X_impl.cc.t
deleted file mode 100644
index 98af5d02fa..0000000000
--- a/gr-analog/lib/random_uniform_source_X_impl.cc.t
+++ /dev/null
@@ -1,83 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2015 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.
- */
-
-/* @WARNING@ */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "@IMPL_NAME@.h"
-#include <gnuradio/io_signature.h>
-
-namespace gr {
- namespace analog {
-
- @BASE_NAME@::sptr
- @BASE_NAME@::make(int minimum, int maximum, int seed)
- {
- return gnuradio::get_initial_sptr(new @IMPL_NAME@(minimum, maximum, seed));
- }
-
- @IMPL_NAME@::@IMPL_NAME@(int minimum, int maximum, int seed)
- : sync_block("@BASE_NAME@",
- io_signature::make(0, 0, 0),
- io_signature::make(1, 1, sizeof(@TYPE@)))
- {
- d_rng = new gr::random(seed, minimum, maximum);
- }
-
- @IMPL_NAME@::~@IMPL_NAME@()
- {
- delete d_rng;
- }
-
- int
- @IMPL_NAME@::random_value()
- {
- return d_rng->ran_int();
- }
-
- int
- @IMPL_NAME@::work(int noutput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items)
- {
- @TYPE@ *out = (@TYPE@*)output_items[0];
-
- for(int i = 0; i < noutput_items; i++){
- *out++ = (@TYPE@) random_value();
- }
-
- // Tell runtime system how many output items we produced.
- return noutput_items;
- }
-
-
-
-
-
-
-
-
- } /* namespace analog */
-} /* namespace gr */
diff --git a/gr-analog/lib/random_uniform_source_impl.cc b/gr-analog/lib/random_uniform_source_impl.cc
new file mode 100644
index 0000000000..cf89cac1e3
--- /dev/null
+++ b/gr-analog/lib/random_uniform_source_impl.cc
@@ -0,0 +1,76 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2015 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.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "random_uniform_source_impl.h"
+#include <gnuradio/io_signature.h>
+
+namespace gr {
+namespace analog {
+
+template <class T>
+typename random_uniform_source<T>::sptr
+random_uniform_source<T>::make(int minimum, int maximum, int seed) {
+ return gnuradio::get_initial_sptr(new random_uniform_source_impl<T>(minimum, maximum, seed));
+}
+
+template <class T>
+random_uniform_source_impl<T>::random_uniform_source_impl(int minimum, int maximum, int seed)
+ : sync_block("random_uniform_source",
+ io_signature::make(0, 0, 0),
+ io_signature::make(1, 1, sizeof(T))) {
+ d_rng = new gr::random(seed, minimum, maximum);
+}
+
+template <class T>
+random_uniform_source_impl<T>::~random_uniform_source_impl() {
+ delete d_rng;
+}
+
+template <class T>
+int random_uniform_source_impl<T>::random_value() {
+ return d_rng->ran_int();
+}
+
+template <class T>
+int random_uniform_source_impl<T>::work(int noutput_items,
+ gr_vector_const_void_star& input_items,
+ gr_vector_void_star& output_items) {
+ T* out = (T*)output_items[0];
+
+ for (int i = 0; i < noutput_items; i++) {
+ *out++ = (T)random_value();
+ }
+
+ // Tell runtime system how many output items we produced.
+ return noutput_items;
+}
+
+template class random_uniform_source<std::uint8_t>;
+template class random_uniform_source<std::int16_t>;
+template class random_uniform_source<std::int32_t>;
+} /* namespace analog */
+} /* namespace gr */
diff --git a/gr-analog/lib/random_uniform_source_X_impl.h.t b/gr-analog/lib/random_uniform_source_impl.h
index 67fcfc9893..65e6c3ef64 100644
--- a/gr-analog/lib/random_uniform_source_X_impl.h.t
+++ b/gr-analog/lib/random_uniform_source_impl.h
@@ -20,25 +20,25 @@
* Boston, MA 02110-1301, USA.
*/
-// @WARNING@
-#ifndef @GUARD_NAME@
-#define @GUARD_NAME@
+#ifndef RANDOM_UNIFORM_SOURCE_IMPL_H
+#define RANDOM_UNIFORM_SOURCE_IMPL_H
-#include <gnuradio/analog/@BASE_NAME@.h>
+#include <gnuradio/analog/random_uniform_source.h>
#include <gnuradio/random.h>
namespace gr {
namespace analog {
- class @IMPL_NAME@ : public @BASE_NAME@
+template<class T>
+ class random_uniform_source_impl : public random_uniform_source<T>
{
private:
gr::random *d_rng;
public:
- @IMPL_NAME@(int minimum, int maximum, int seed);
- ~@IMPL_NAME@();
+ random_uniform_source_impl(int minimum, int maximum, int seed);
+ ~random_uniform_source_impl();
// Where all the action really happens
int work(int noutput_items,
@@ -51,4 +51,4 @@ namespace gr {
} /* namespace filter */
} /* namespace gr */
-#endif /* @GUARD_NAME@ */ \ No newline at end of file
+#endif /* RANDOM_UNIFORM_SOURCE_IMPL_H */
diff --git a/gr-analog/lib/sig_source_X_impl.cc.t b/gr-analog/lib/sig_source_X_impl.cc.t
deleted file mode 100644
index 18a45f5801..0000000000
--- a/gr-analog/lib/sig_source_X_impl.cc.t
+++ /dev/null
@@ -1,287 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2004,2010,2012,2018 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.
- */
-
-/* @WARNING@ */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "@IMPL_NAME@.h"
-#include <gnuradio/io_signature.h>
-#include <gnuradio/gr_complex.h>
-#include <gnuradio/math.h>
-
-#include <stdexcept>
-#include <algorithm>
-
-namespace gr {
- namespace analog {
-
- @BASE_NAME@::sptr
- @BASE_NAME@::make(double sampling_freq, gr_waveform_t waveform,
- double frequency, double ampl, @TYPE@ offset)
- {
- return gnuradio::get_initial_sptr
- (new @IMPL_NAME@(sampling_freq, waveform, frequency, ampl, offset));
- }
-
- @IMPL_NAME@::@IMPL_NAME@(double sampling_freq, gr_waveform_t waveform,
- double frequency, double ampl, @TYPE@ offset)
- : sync_block("@BASE_NAME@",
- io_signature::make(0, 0, 0),
- io_signature::make(1, 1, sizeof(@TYPE@))),
- d_sampling_freq(sampling_freq), d_waveform(waveform),
- d_frequency(frequency), d_ampl(ampl), d_offset(offset)
- {
- set_frequency(frequency);
-
- message_port_register_in(pmt::mp("freq"));
- set_msg_handler(pmt::mp("freq"), boost::bind(&@IMPL_NAME@::set_frequency_msg, this, _1));
- }
-
- @IMPL_NAME@::~@IMPL_NAME@()
- {
- }
-
- void
- @IMPL_NAME@::set_frequency_msg(pmt::pmt_t msg)
- {
- // Accepts either a number that is assumed to be the new
- // frequency or a key:value pair message where the key must be
- // "freq" and the value is the new frequency.
-
- if(pmt::is_number(msg)) {
- set_frequency(pmt::to_double(msg));
- }
- else if(pmt::is_pair(msg)) {
- pmt::pmt_t key = pmt::car(msg);
- pmt::pmt_t val = pmt::cdr(msg);
- if(pmt::eq(key, pmt::intern("freq"))) {
- if(pmt::is_number(val)) {
- set_frequency(pmt::to_double(val));
- }
- }
- else {
- GR_LOG_WARN(d_logger, boost::format("Set Frequency Message must have "
- "the key = 'freq'; got '%1%'.") \
- % pmt::write_string(key));
- }
- }
- else {
- GR_LOG_WARN(d_logger, "Set Frequency Message must be either a number or a "
- "key:value pair where the key is 'freq'.");
- }
- }
-
- int
- @IMPL_NAME@::work(int noutput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items)
- {
- @TYPE@ *optr = (@TYPE@*)output_items[0];
- @TYPE@ t;
-
- switch(d_waveform) {
-
-#if @IS_COMPLEX@ // complex?
-
- case GR_CONST_WAVE:
- t = (gr_complex) d_ampl + d_offset;
- std::fill_n(optr, noutput_items, t);
- break;
-
- case GR_SIN_WAVE:
- case GR_COS_WAVE:
- d_nco.sincos(optr, noutput_items, d_ampl);
- if(d_offset == gr_complex(0,0))
- break;
-
- for(int i = 0; i < noutput_items; i++) {
- optr[i] += d_offset;
- }
- break;
-
- /* Implements a real square wave high from -PI to 0.
- * The imaginary square wave leads by 90 deg.
- */
- case GR_SQR_WAVE:
- for(int i = 0; i < noutput_items; i++) {
- if(d_nco.get_phase() < -1*GR_M_PI/2)
- optr[i] = gr_complex(d_ampl, 0) + d_offset;
- else if(d_nco.get_phase() < 0)
- optr[i] = gr_complex(d_ampl, d_ampl) + d_offset;
- else if(d_nco.get_phase() < GR_M_PI/2)
- optr[i] = gr_complex(0, d_ampl) + d_offset;
- else
- optr[i] = d_offset;
- d_nco.step();
- }
- break;
-
- /* Implements a real triangle wave rising from -PI to 0 and
- * falling from 0 to PI. The imaginary triangle wave leads by
- * 90 deg.
- */
- case GR_TRI_WAVE:
- for(int i = 0; i < noutput_items; i++) {
- if(d_nco.get_phase() < -1*GR_M_PI/2){
- optr[i] = gr_complex(d_ampl*d_nco.get_phase()/GR_M_PI + d_ampl,
- -1*d_ampl*d_nco.get_phase()/GR_M_PI - d_ampl/2) + d_offset;
- }
- else if(d_nco.get_phase() < 0) {
- optr[i] = gr_complex(d_ampl*d_nco.get_phase()/GR_M_PI + d_ampl,
- d_ampl*d_nco.get_phase()/GR_M_PI + d_ampl/2) + d_offset;
- }
- else if(d_nco.get_phase() < GR_M_PI/2) {
- optr[i] = gr_complex(-1*d_ampl*d_nco.get_phase()/GR_M_PI + d_ampl,
- d_ampl*d_nco.get_phase()/GR_M_PI + d_ampl/2) + d_offset;
- }
- else {
- optr[i] = gr_complex(-1*d_ampl*d_nco.get_phase()/GR_M_PI + d_ampl,
- -1*d_ampl*d_nco.get_phase()/GR_M_PI + 3*d_ampl/2) + d_offset;
- }
- d_nco.step();
- }
- break;
-
- /* Implements a real saw tooth wave rising from -PI to PI.
- * The imaginary saw tooth wave leads by 90 deg.
- */
- case GR_SAW_WAVE:
- for(int i = 0; i < noutput_items; i++) {
- if(d_nco.get_phase() < -1*GR_M_PI/2) {
- optr[i] = gr_complex(d_ampl*d_nco.get_phase()/(2*GR_M_PI) + d_ampl/2,
- d_ampl*d_nco.get_phase()/(2*GR_M_PI) + 5*d_ampl/4) + d_offset;
- }
- else {
- optr[i] = gr_complex(d_ampl*d_nco.get_phase()/(2*GR_M_PI) + d_ampl/2,
- d_ampl*d_nco.get_phase()/(2*GR_M_PI) + d_ampl/4) + d_offset;
- }
- d_nco.step();
- }
- break;
-
-#else // nope...
-
- case GR_CONST_WAVE:
- t = (@TYPE@)d_ampl + d_offset;
- std::fill_n(optr, noutput_items, t);
- break;
-
- case GR_SIN_WAVE:
- d_nco.sin(optr, noutput_items, d_ampl);
- if(d_offset == 0)
- break;
-
- for(int i = 0; i < noutput_items; i++) {
- optr[i] += d_offset;
- }
- break;
-
- case GR_COS_WAVE:
- d_nco.cos(optr, noutput_items, d_ampl);
- if(d_offset == 0)
- break;
-
- for(int i = 0; i < noutput_items; i++) {
- optr[i] += d_offset;
- }
- break;
-
- /* The square wave is high from -PI to 0. */
- case GR_SQR_WAVE:
- t = (@TYPE@)d_ampl + d_offset;
- for(int i = 0; i < noutput_items; i++) {
- if(d_nco.get_phase() < 0)
- optr[i] = t;
- else
- optr[i] = d_offset;
- d_nco.step();
- }
- break;
-
- /* The triangle wave rises from -PI to 0 and falls from 0 to PI. */
- case GR_TRI_WAVE:
- for(int i = 0; i < noutput_items; i++) {
- double t = d_ampl*d_nco.get_phase()/GR_M_PI;
- if (d_nco.get_phase() < 0)
- optr[i] = static_cast<@TYPE@>(t + d_ampl + d_offset);
- else
- optr[i] = static_cast<@TYPE@>(-1*t + d_ampl + d_offset);
- d_nco.step();
- }
- break;
-
- /* The saw tooth wave rises from -PI to PI. */
- case GR_SAW_WAVE:
- for(int i = 0; i < noutput_items; i++) {
- t = static_cast<@TYPE@>(d_ampl*d_nco.get_phase()/(2*GR_M_PI)
- + d_ampl/2 + d_offset);
- optr[i] = t;
- d_nco.step();
- }
- break;
-
-#endif
-
- default:
- throw std::runtime_error("analog::sig_source: invalid waveform");
- }
-
- return noutput_items;
- }
-
- void
- @NAME@::set_sampling_freq(double sampling_freq)
- {
- d_sampling_freq = sampling_freq;
- d_nco.set_freq (2 * GR_M_PI * d_frequency / d_sampling_freq);
- }
-
- void
- @NAME@::set_waveform(gr_waveform_t waveform)
- {
- d_waveform = waveform;
- }
-
- void
- @NAME@::set_frequency(double frequency)
- {
- d_frequency = frequency;
- d_nco.set_freq(2 * GR_M_PI * d_frequency / d_sampling_freq);
- }
-
- void
- @NAME@::set_amplitude(double ampl)
- {
- d_ampl = ampl;
- }
-
- void
- @NAME@::set_offset(@TYPE@ offset)
- {
- d_offset = offset;
- }
-
- } /* namespace analog */
-} /* namespace gr */
diff --git a/gr-analog/lib/sig_source_impl.cc b/gr-analog/lib/sig_source_impl.cc
new file mode 100644
index 0000000000..0f7ced0eb2
--- /dev/null
+++ b/gr-analog/lib/sig_source_impl.cc
@@ -0,0 +1,287 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2010,2012,2018 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.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "sig_source_impl.h"
+#include <gnuradio/gr_complex.h>
+#include <gnuradio/io_signature.h>
+#include <gnuradio/math.h>
+
+#include <algorithm>
+#include <stdexcept>
+
+namespace gr {
+namespace analog {
+
+template <class T>
+typename sig_source<T>::sptr sig_source<T>::make(
+ double sampling_freq, gr_waveform_t waveform, double frequency, double ampl, T offset) {
+ return gnuradio::get_initial_sptr(
+ new sig_source_impl<T>(sampling_freq, waveform, frequency, ampl, offset));
+}
+
+template <class T>
+sig_source_impl<T>::sig_source_impl(
+ double sampling_freq, gr_waveform_t waveform, double frequency, double ampl, T offset)
+ : sync_block("sig_source", io_signature::make(0, 0, 0), io_signature::make(1, 1, sizeof(T))),
+ d_sampling_freq(sampling_freq), d_waveform(waveform), d_frequency(frequency), d_ampl(ampl),
+ d_offset(offset) {
+ this->set_frequency(frequency);
+
+ this->message_port_register_in(pmt::mp("freq"));
+ this->set_msg_handler(pmt::mp("freq"), boost::bind(&sig_source_impl<T>::set_frequency_msg, this, _1));
+}
+
+template <class T>
+sig_source_impl<T>::~sig_source_impl() {}
+
+template <class T>
+void sig_source_impl<T>::set_frequency_msg(pmt::pmt_t msg) {
+ // Accepts either a number that is assumed to be the new
+ // frequency or a key:value pair message where the key must be
+ // "freq" and the value is the new frequency.
+
+ if (pmt::is_number(msg)) {
+ set_frequency(pmt::to_double(msg));
+ } else if (pmt::is_pair(msg)) {
+ pmt::pmt_t key = pmt::car(msg);
+ pmt::pmt_t val = pmt::cdr(msg);
+ if (pmt::eq(key, pmt::intern("freq"))) {
+ if (pmt::is_number(val)) {
+ set_frequency(pmt::to_double(val));
+ }
+ } else {
+ GR_LOG_WARN(this->d_logger,
+ boost::format("Set Frequency Message must have "
+ "the key = 'freq'; got '%1%'.") %
+ pmt::write_string(key));
+ }
+ } else {
+ GR_LOG_WARN(this->d_logger,
+ "Set Frequency Message must be either a number or a "
+ "key:value pair where the key is 'freq'.");
+ }
+}
+
+template <class T>
+int sig_source_impl<T>::work(int noutput_items,
+ gr_vector_const_void_star& input_items,
+ gr_vector_void_star& output_items) {
+ T* optr = (T*)output_items[0];
+ T t;
+
+ switch (d_waveform) {
+ case GR_CONST_WAVE:
+ t = (T)d_ampl + d_offset;
+ std::fill_n(optr, noutput_items, t);
+ break;
+
+ case GR_SIN_WAVE:
+ d_nco.sin(optr, noutput_items, d_ampl);
+ if (d_offset == 0)
+ break;
+
+ for (int i = 0; i < noutput_items; i++) {
+ optr[i] += d_offset;
+ }
+ break;
+
+ case GR_COS_WAVE:
+ d_nco.cos(optr, noutput_items, d_ampl);
+ if (d_offset == 0)
+ break;
+
+ for (int i = 0; i < noutput_items; i++) {
+ optr[i] += d_offset;
+ }
+ break;
+
+ /* The square wave is high from -PI to 0. */
+ case GR_SQR_WAVE:
+ t = (T)d_ampl + d_offset;
+ for (int i = 0; i < noutput_items; i++) {
+ if (d_nco.get_phase() < 0)
+ optr[i] = t;
+ else
+ optr[i] = d_offset;
+ d_nco.step();
+ }
+ break;
+
+ /* The triangle wave rises from -PI to 0 and falls from 0 to PI. */
+ case GR_TRI_WAVE:
+ for (int i = 0; i < noutput_items; i++) {
+ double t = d_ampl * d_nco.get_phase() / GR_M_PI;
+ if (d_nco.get_phase() < 0)
+ optr[i] = static_cast<T>(t + d_ampl + d_offset);
+ else
+ optr[i] = static_cast<T>(-1 * t + d_ampl + d_offset);
+ d_nco.step();
+ }
+ break;
+
+ /* The saw tooth wave rises from -PI to PI. */
+ case GR_SAW_WAVE:
+ for (int i = 0; i < noutput_items; i++) {
+ t = static_cast<T>(d_ampl * d_nco.get_phase() / (2 * GR_M_PI) + d_ampl / 2 + d_offset);
+ optr[i] = t;
+ d_nco.step();
+ }
+ break;
+ default:
+ throw std::runtime_error("analog::sig_source: invalid waveform");
+ }
+
+ return noutput_items;
+}
+
+
+template <>
+int sig_source_impl<gr_complex>::work(int noutput_items,
+ gr_vector_const_void_star& input_items,
+ gr_vector_void_star& output_items) {
+ gr_complex* optr = (gr_complex*)output_items[0];
+ gr_complex t;
+
+ switch (d_waveform) {
+ case GR_CONST_WAVE:
+ t = (gr_complex)d_ampl + d_offset;
+ std::fill_n(optr, noutput_items, t);
+ break;
+
+ case GR_SIN_WAVE:
+ case GR_COS_WAVE:
+ d_nco.sincos(optr, noutput_items, d_ampl);
+ if (d_offset == gr_complex(0, 0))
+ break;
+
+ for (int i = 0; i < noutput_items; i++) {
+ optr[i] += d_offset;
+ }
+ break;
+
+ /* Implements a real square wave high from -PI to 0.
+ * The imaginary square wave leads by 90 deg.
+ */
+ case GR_SQR_WAVE:
+ for (int i = 0; i < noutput_items; i++) {
+ if (d_nco.get_phase() < -1 * GR_M_PI / 2)
+ optr[i] = gr_complex(d_ampl, 0) + d_offset;
+ else if (d_nco.get_phase() < 0)
+ optr[i] = gr_complex(d_ampl, d_ampl) + d_offset;
+ else if (d_nco.get_phase() < GR_M_PI / 2)
+ optr[i] = gr_complex(0, d_ampl) + d_offset;
+ else
+ optr[i] = d_offset;
+ d_nco.step();
+ }
+ break;
+
+ /* Implements a real triangle wave rising from -PI to 0 and
+ * falling from 0 to PI. The imaginary triangle wave leads by
+ * 90 deg.
+ */
+ case GR_TRI_WAVE:
+ for (int i = 0; i < noutput_items; i++) {
+ if (d_nco.get_phase() < -1 * GR_M_PI / 2) {
+ optr[i] = gr_complex(d_ampl * d_nco.get_phase() / GR_M_PI + d_ampl,
+ -1 * d_ampl * d_nco.get_phase() / GR_M_PI - d_ampl / 2) +
+ d_offset;
+ } else if (d_nco.get_phase() < 0) {
+ optr[i] = gr_complex(d_ampl * d_nco.get_phase() / GR_M_PI + d_ampl,
+ d_ampl * d_nco.get_phase() / GR_M_PI + d_ampl / 2) +
+ d_offset;
+ } else if (d_nco.get_phase() < GR_M_PI / 2) {
+ optr[i] = gr_complex(-1 * d_ampl * d_nco.get_phase() / GR_M_PI + d_ampl,
+ d_ampl * d_nco.get_phase() / GR_M_PI + d_ampl / 2) +
+ d_offset;
+ } else {
+ optr[i] = gr_complex(-1 * d_ampl * d_nco.get_phase() / GR_M_PI + d_ampl,
+ -1 * d_ampl * d_nco.get_phase() / GR_M_PI + 3 * d_ampl / 2) +
+ d_offset;
+ }
+ d_nco.step();
+ }
+ break;
+
+ /* Implements a real saw tooth wave rising from -PI to PI.
+ * The imaginary saw tooth wave leads by 90 deg.
+ */
+ case GR_SAW_WAVE:
+ for (int i = 0; i < noutput_items; i++) {
+ if (d_nco.get_phase() < -1 * GR_M_PI / 2) {
+ optr[i] = gr_complex(d_ampl * d_nco.get_phase() / (2 * GR_M_PI) + d_ampl / 2,
+ d_ampl * d_nco.get_phase() / (2 * GR_M_PI) + 5 * d_ampl / 4) +
+ d_offset;
+ } else {
+ optr[i] = gr_complex(d_ampl * d_nco.get_phase() / (2 * GR_M_PI) + d_ampl / 2,
+ d_ampl * d_nco.get_phase() / (2 * GR_M_PI) + d_ampl / 4) +
+ d_offset;
+ }
+ d_nco.step();
+ }
+ break;
+ default:
+ throw std::runtime_error("analog::sig_source: invalid waveform");
+ }
+
+ return noutput_items;
+}
+
+
+template <class T>
+void sig_source_impl<T>::set_sampling_freq(double sampling_freq) {
+ d_sampling_freq = sampling_freq;
+ d_nco.set_freq(2 * GR_M_PI * this->d_frequency / this->d_sampling_freq);
+}
+
+template <class T>
+void sig_source_impl<T>::set_waveform(gr_waveform_t waveform) {
+ d_waveform = waveform;
+}
+
+template <class T>
+void sig_source_impl<T>::set_frequency(double frequency) {
+ d_frequency = frequency;
+ d_nco.set_freq(2 * GR_M_PI * this->d_frequency / this->d_sampling_freq);
+}
+
+template <class T>
+void sig_source_impl<T>::set_amplitude(double ampl) {
+ d_ampl = ampl;
+}
+
+template <class T>
+void sig_source_impl<T>::set_offset(T offset) {
+ d_offset = offset;
+}
+
+template class sig_source<std::int16_t>;
+template class sig_source<std::int32_t>;
+template class sig_source<float>;
+template class sig_source<gr_complex>;
+} /* namespace analog */
+} /* namespace gr */
diff --git a/gr-analog/lib/sig_source_X_impl.h.t b/gr-analog/lib/sig_source_impl.h
index f5dfd5c4f6..9fd26582fa 100644
--- a/gr-analog/lib/sig_source_X_impl.h.t
+++ b/gr-analog/lib/sig_source_impl.h
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2004,2012 Free Software Foundation, Inc.
+ * Copyright 2004,2012,2018 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -20,32 +20,32 @@
* Boston, MA 02110-1301, USA.
*/
-/* @WARNING@ */
-#ifndef @GUARD_NAME@
-#define @GUARD_NAME@
+#ifndef SIG_SOURCE_IMPL_H
+#define SIG_SOURCE_IMPL_H
-#include <gnuradio/analog/@BASE_NAME@.h>
+#include <gnuradio/analog/sig_source.h>
#include <gnuradio/sync_block.h>
#include <gnuradio/fxpt_nco.h>
namespace gr {
namespace analog {
- class @IMPL_NAME@ : public @BASE_NAME@
+template<class T>
+ class sig_source_impl : public sig_source<T>
{
private:
double d_sampling_freq;
gr_waveform_t d_waveform;
double d_frequency;
double d_ampl;
- @TYPE@ d_offset;
+ T d_offset;
gr::fxpt_nco d_nco;
public:
- @IMPL_NAME@(double sampling_freq, gr_waveform_t waveform,
- double wave_freq, double ampl, @TYPE@ offset = 0);
- ~@IMPL_NAME@();
+ sig_source_impl(double sampling_freq, gr_waveform_t waveform,
+ double wave_freq, double ampl, T offset = 0);
+ ~sig_source_impl();
virtual int work(int noutput_items,
gr_vector_const_void_star &input_items,
@@ -55,17 +55,17 @@ namespace gr {
gr_waveform_t waveform() const { return d_waveform; }
double frequency() const { return d_frequency; }
double amplitude() const { return d_ampl; }
- @TYPE@ offset() const { return d_offset; }
+ T offset() const { return d_offset; }
void set_sampling_freq(double sampling_freq);
void set_waveform(gr_waveform_t waveform);
void set_frequency_msg(pmt::pmt_t msg);
void set_frequency(double frequency);
void set_amplitude(double ampl);
- void set_offset(@TYPE@ offset);
+ void set_offset(T offset);
};
} /* namespace analog */
} /* namespace gr */
-#endif /* @GUARD_NAME@ */
+#endif /* SIG_SOURCE_IMPL_H */