diff options
author | Marcus Müller <marcus@hostalia.de> | 2018-08-31 23:02:22 +0200 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2018-08-31 23:02:22 +0200 |
commit | 254fe5e89403d4de1fa6663d09efdf946996aff3 (patch) | |
tree | 62877d7ac7fdedf6c397c51e22ac6f97eba97ddf /gr-analog/lib | |
parent | 896d1c9da31963ecf5b0d90942c2af51ca998a69 (diff) | |
parent | 5ad935c3a3dd46ce2860b13e2b774e4841784616 (diff) |
Merge remote-tracking branch 'origin/next' into merge_next
Diffstat (limited to 'gr-analog/lib')
23 files changed, 804 insertions, 805 deletions
diff --git a/gr-analog/lib/CMakeLists.txt b/gr-analog/lib/CMakeLists.txt index cc4864d6d1..9a41d12fe7 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 ) @@ -106,14 +100,13 @@ list(APPEND analog_libs add_library(gnuradio-analog SHARED ${analog_sources}) target_link_libraries(gnuradio-analog ${analog_libs}) -GR_LIBRARY_FOO(gnuradio-analog RUNTIME_COMPONENT "analog_runtime" DEVEL_COMPONENT "analog_devel") -add_dependencies(gnuradio-analog analog_generated_includes analog_generated_swigs gnuradio-filter) +GR_LIBRARY_FOO(gnuradio-analog) +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) @@ -122,7 +115,7 @@ if(ENABLE_STATIC_LIBS) endif(NOT WIN32) install(TARGETS gnuradio-analog_static - ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT "analog_devel" # .lib file + ARCHIVE DESTINATION lib${LIB_SUFFIX} # .lib file ) endif(ENABLE_STATIC_LIBS) diff --git a/gr-analog/lib/cpfsk_bc_impl.cc b/gr-analog/lib/cpfsk_bc_impl.cc index 3c1674aaa4..01b3ae3ebd 100644 --- a/gr-analog/lib/cpfsk_bc_impl.cc +++ b/gr-analog/lib/cpfsk_bc_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008,2010,2012 Free Software Foundation, Inc. + * Copyright 2008,2010,2012,2018 Free Software Foundation, Inc. * * 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 @@ -25,12 +25,11 @@ #include "cpfsk_bc_impl.h" #include <gnuradio/io_signature.h> #include <gnuradio/expj.h> +#include <gnuradio/math.h> namespace gr { namespace analog { -#define M_TWOPI (2*M_PI) - cpfsk_bc::sptr cpfsk_bc::make(float k, float ampl, int samples_per_sym) { @@ -45,7 +44,7 @@ namespace gr { samples_per_sym) { d_samples_per_sym = samples_per_sym; - d_freq = k*M_PI/samples_per_sym; + d_freq = k*GR_M_PI/samples_per_sym; d_ampl = ampl; d_phase = 0.0; } @@ -69,10 +68,10 @@ namespace gr { else d_phase -= d_freq; - while(d_phase > M_TWOPI) - d_phase -= M_TWOPI; - while(d_phase < -M_TWOPI) - d_phase += M_TWOPI; + while(d_phase > GR_M_TWOPI) + d_phase -= GR_M_TWOPI; + while(d_phase < -GR_M_TWOPI) + d_phase += GR_M_TWOPI; *out++ = gr_expj(d_phase)*d_ampl; } diff --git a/gr-analog/lib/cpm.cc b/gr-analog/lib/cpm.cc index b61ee28816..163588682d 100644 --- a/gr-analog/lib/cpm.cc +++ b/gr-analog/lib/cpm.cc @@ -24,29 +24,23 @@ #include "config.h" #endif -#include <cmath> -#include <cfloat> #include <gnuradio/analog/cpm.h> +#include <gnuradio/math.h> -//gives us erf on compilers without it -#include <boost/math/special_functions/erf.hpp> -namespace bm = boost::math; +#include <cmath> +#include <cfloat> namespace gr { namespace analog { -#ifndef M_TWOPI -# define M_TWOPI (2*M_PI) -#endif - - //! Normalised sinc function, sinc(x)=sin(pi*x)/pi*x + //! Normalised sinc function, sinc(x)=std::sin(pi*x)/pi*x inline double sinc(double x) { if(x == 0) { return 1.0; } - return sin(M_PI * x) / (M_PI * x); + return std::sin(GR_M_PI * x) / (GR_M_PI * x); } @@ -56,7 +50,7 @@ namespace gr { { std::vector<float> taps(samples_per_sym * L, 1.0/L/samples_per_sym); for(unsigned i = 0; i < samples_per_sym * L; i++) { - taps[i] *= 1 - cos(M_TWOPI * i / L / samples_per_sym); + taps[i] *= 1 - std::cos(GR_M_TWOPI * i / L / samples_per_sym); } return taps; @@ -67,7 +61,7 @@ namespace gr { * * L-SRC has a time-continuous phase response function of * - * g(t) = 1/LT * sinc(2t/LT) * cos(beta * 2pi t / LT) / (1 - (4beta / LT * t)^2) + * g(t) = 1/LT * sinc(2t/LT) * std::cos(beta * 2pi t / LT) / (1 - (4beta / LT * t)^2) * * which is the Fourier transform of a cos-rolloff function with rolloff * beta, and looks like a sinc-function, multiplied with a rolloff term. @@ -75,7 +69,7 @@ namespace gr { * zero crossings. * The time-discrete IR is thus * - * g(k) = 1/Ls * sinc(2k/Ls) * cos(beta * pi k / Ls) / (1 - (4beta / Ls * k)^2) + * g(k) = 1/Ls * sinc(2k/Ls) * std::cos(beta * pi k / Ls) / (1 - (4beta / Ls * k)^2) * where k = 0...Ls-1 * and s = samples per symbol. */ @@ -100,7 +94,7 @@ namespace gr { } else { double tmp = 4.0 * beta * k / Ls; - taps_d[i] *= cos(beta * M_TWOPI * k / Ls) / (1 - tmp * tmp); + taps_d[i] *= std::cos(beta * GR_M_TWOPI * k / Ls) / (1 - tmp * tmp); } sum += taps_d[i]; } @@ -127,8 +121,8 @@ namespace gr { } const double pi2_24 = 0.411233516712057; // pi^2/24 - double f = M_PI * k / sps; - return sinc(k/sps) - pi2_24 * (2 * sin(f) - 2*f*cos(f) - f*f*sin(f)) / (f*f*f); + double f = GR_M_PI * k / sps; + return sinc(k/sps) - pi2_24 * (2 * std::sin(f) - 2*f*std::cos(f) - f*f*std::sin(f)) / (f*f*f); } //! Taps for TFM CPM (Tamed frequency modulation) @@ -183,8 +177,8 @@ namespace gr { double alpha = 5.336446256636997 * bt; for(unsigned i = 0; i < samples_per_sym * L; i++) { double k = i - Ls/2; // Causal to acausal - taps_d[i] = (bm::erf(alpha * (k / samples_per_sym + 0.5)) - - bm::erf(alpha * (k / samples_per_sym - 0.5))) + taps_d[i] = (std::erf(alpha * (k / samples_per_sym + 0.5)) - + std::erf(alpha * (k / samples_per_sym - 0.5))) * 0.5 / samples_per_sym; taps[i] = (float) taps_d[i]; } 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 72c6cb0582..0000000000 --- a/gr-analog/lib/fastnoise_source_X_impl.cc.t +++ /dev/null @@ -1,171 +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/xoroshiro128p.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_samples.resize(samples); - xoroshiro128p_seed(d_state, (uint64_t) seed); - 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() - { - size_t idx = xoroshiro128p_next(d_state) % d_samples.size(); - return d_samples[idx]; - } - - @TYPE@ @IMPL_NAME@::sample_unbiased() - { - uint64_t random_int = xoroshiro128p_next(d_state); -#if @IS_COMPLEX@ - gr_complex s(sample()); - float re = (random_int & (UINT64_C(1)<<23)) ? (- s.real()) : (s.real()); - float im = (random_int & (UINT64_C(1)<<42)) ? (- s.real()) : (s.real()); - return gr_complex(re, im); -#else - float s = sample(); - return (random_int & (1<<23)) ? (-s) : s; -#endif - } - - const std::vector<@TYPE@>& @IMPL_NAME@::samples() const - { - return d_samples; - } - } /* 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..9cdea4e50d --- /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/xoroshiro128p.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_samples.resize(samples); + xoroshiro128p_seed(d_state, (uint64_t) seed); + 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_samples.resize(samples); + xoroshiro128p_seed(d_state, (uint64_t) seed); + 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() { + size_t idx = xoroshiro128p_next(d_state) % d_samples.size(); + return d_samples[idx]; +} + +template <class T> +T fastnoise_source_impl<T>::sample_unbiased() { + uint64_t random_int = xoroshiro128p_next(d_state); + float s = sample(); + return (random_int & (1<<23)) ? (-s) : s; +} + +template <> +gr_complex fastnoise_source_impl<gr_complex>::sample_unbiased() { + uint64_t random_int = xoroshiro128p_next(d_state); + float re = (random_int & (UINT64_C(1)<<23)) ? (- s.real()) : (s.real()); + float im = (random_int & (UINT64_C(1)<<42)) ? (- s.real()) : (s.real()); + return gr_complex(re, im); +} + +template <class T> +const std::vector<T>& fast_noise_source_impl<T>::samples() const { + return d_samples; +} + + +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 ef0465729d..f40d39d5f1 100644 --- a/gr-analog/lib/fastnoise_source_X_impl.h.t +++ b/gr-analog/lib/fastnoise_source_impl.h @@ -20,37 +20,38 @@ * 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> +#include <vector> 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; uint64_t d_state[2]; 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(); + const std::vector<T>& samples() const; void set_type(noise_type_t type); void set_amplitude(float ampl); void generate(); - const std::vector<@TYPE@>& samples() const; noise_type_t type() const { return d_type; } float amplitude() const { return d_ampl; } @@ -63,4 +64,4 @@ namespace gr { } /* namespace filter */ } /* namespace gr */ -#endif /* @GUARD_NAME@ */ +#endif /* FASTNOISE_SOURCE_IMPL_H */ diff --git a/gr-analog/lib/feedforward_agc_cc_impl.cc b/gr-analog/lib/feedforward_agc_cc_impl.cc index 9870c7c3c0..1a7ba7b9c4 100644 --- a/gr-analog/lib/feedforward_agc_cc_impl.cc +++ b/gr-analog/lib/feedforward_agc_cc_impl.cc @@ -54,12 +54,6 @@ namespace gr { { } - inline static float - mag_squared(gr_complex x) - { - return x.real() * x.real() + x.imag() * x.imag(); - } - // approximate sqrt(x^2 + y^2) inline static float envelope(gr_complex x) diff --git a/gr-analog/lib/fmdet_cf_impl.cc b/gr-analog/lib/fmdet_cf_impl.cc index a9b372478a..fdd438f335 100644 --- a/gr-analog/lib/fmdet_cf_impl.cc +++ b/gr-analog/lib/fmdet_cf_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008,2010,2012 Free Software Foundation, Inc. + * Copyright 2008,2010,2012,2018 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gr-analog/lib/frequency_modulator_fc_impl.cc b/gr-analog/lib/frequency_modulator_fc_impl.cc index 56fa0f7c17..0c7f9873b1 100644 --- a/gr-analog/lib/frequency_modulator_fc_impl.cc +++ b/gr-analog/lib/frequency_modulator_fc_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2010-2012 Free Software Foundation, Inc. + * Copyright 2004,2010-2012,2018 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -27,6 +27,7 @@ #include "frequency_modulator_fc_impl.h" #include <gnuradio/io_signature.h> #include <gnuradio/fxpt.h> +#include <gnuradio/math.h> #include <cmath> namespace gr { @@ -63,7 +64,7 @@ namespace gr { d_phase = d_phase + d_sensitivity * in[i]; //place phase in [-pi, +pi[ - #define F_PI ((float)(M_PI)) + #define F_PI ((float)(GR_M_PI)) d_phase = std::fmod(d_phase + F_PI, 2.0f * F_PI) - F_PI; float oi, oq; 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/pll_carriertracking_cc_impl.cc b/gr-analog/lib/pll_carriertracking_cc_impl.cc index 0cc3f8b8ec..bf8b219189 100644 --- a/gr-analog/lib/pll_carriertracking_cc_impl.cc +++ b/gr-analog/lib/pll_carriertracking_cc_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006,2010-2013 Free Software Foundation, Inc. + * Copyright 2006,2010-2013,2018 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -27,16 +27,13 @@ #include "pll_carriertracking_cc_impl.h" #include <gnuradio/io_signature.h> #include <gnuradio/sincos.h> -#include <math.h> #include <gnuradio/math.h> +#include <cmath> + namespace gr { namespace analog { -#ifndef M_TWOPI -#define M_TWOPI (2.0f*M_PI) -#endif - pll_carriertracking_cc::sptr pll_carriertracking_cc::make(float loop_bw, float max_freq, float min_freq) { @@ -62,10 +59,10 @@ namespace gr { float pll_carriertracking_cc_impl::mod_2pi(float in) { - if(in>M_PI) - return in-M_TWOPI; - else if(in<-M_PI) - return in+M_TWOPI; + if(in>GR_M_PI) + return in-GR_M_TWOPI; + else if(in<-GR_M_PI) + return in+GR_M_TWOPI; else return in; } diff --git a/gr-analog/lib/pll_freqdet_cf_impl.cc b/gr-analog/lib/pll_freqdet_cf_impl.cc index 42caa0bfd5..46c9a9f954 100644 --- a/gr-analog/lib/pll_freqdet_cf_impl.cc +++ b/gr-analog/lib/pll_freqdet_cf_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2010,2011 Free Software Foundation, Inc. + * Copyright 2004,2010,2011,2018 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -26,16 +26,13 @@ #include "pll_freqdet_cf_impl.h" #include <gnuradio/io_signature.h> -#include <math.h> #include <gnuradio/math.h> +#include <cmath> + namespace gr { namespace analog { -#ifndef M_TWOPI -#define M_TWOPI (2.0f*M_PI) -#endif - pll_freqdet_cf::sptr pll_freqdet_cf::make(float loop_bw, float max_freq, float min_freq) { @@ -58,10 +55,10 @@ namespace gr { float pll_freqdet_cf_impl::mod_2pi(float in) { - if(in > M_PI) - return in - M_TWOPI; - else if(in < -M_PI) - return in + M_TWOPI; + if(in > GR_M_PI) + return in - GR_M_TWOPI; + else if(in < -GR_M_PI) + return in + GR_M_TWOPI; else return in; } diff --git a/gr-analog/lib/pll_refout_cc_impl.cc b/gr-analog/lib/pll_refout_cc_impl.cc index 4822263a9c..4cf3574bc7 100644 --- a/gr-analog/lib/pll_refout_cc_impl.cc +++ b/gr-analog/lib/pll_refout_cc_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2010-2013 Free Software Foundation, Inc. + * Copyright 2004,2010-2013,2018 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -33,10 +33,6 @@ namespace gr { namespace analog { -#ifndef M_TWOPI -#define M_TWOPI (2.0f*M_PI) -#endif - pll_refout_cc::sptr pll_refout_cc::make(float loop_bw, float max_freq, float min_freq) { @@ -59,10 +55,10 @@ namespace gr { float pll_refout_cc_impl::mod_2pi(float in) { - if(in > M_PI) - return in - M_TWOPI; - else if(in < -M_PI) - return in+ M_TWOPI; + if(in > GR_M_PI) + return in - GR_M_TWOPI; + else if(in < -GR_M_PI) + return in+ GR_M_TWOPI; else return in; } 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 017177eae0..0000000000 --- a/gr-analog/lib/sig_source_X_impl.cc.t +++ /dev/null @@ -1,286 +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 <algorithm> -#include <gnuradio/io_signature.h> -#include <stdexcept> -#include <algorithm> -#include <gnuradio/gr_complex.h> - -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*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() < 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*M_PI/2){ - optr[i] = gr_complex(d_ampl*d_nco.get_phase()/M_PI + d_ampl, - -1*d_ampl*d_nco.get_phase()/M_PI - d_ampl/2) + d_offset; - } - else if(d_nco.get_phase() < 0) { - optr[i] = gr_complex(d_ampl*d_nco.get_phase()/M_PI + d_ampl, - d_ampl*d_nco.get_phase()/M_PI + d_ampl/2) + d_offset; - } - else if(d_nco.get_phase() < M_PI/2) { - optr[i] = gr_complex(-1*d_ampl*d_nco.get_phase()/M_PI + d_ampl, - d_ampl*d_nco.get_phase()/M_PI + d_ampl/2) + d_offset; - } - else { - optr[i] = gr_complex(-1*d_ampl*d_nco.get_phase()/M_PI + d_ampl, - -1*d_ampl*d_nco.get_phase()/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*M_PI/2) { - optr[i] = gr_complex(d_ampl*d_nco.get_phase()/(2*M_PI) + d_ampl/2, - d_ampl*d_nco.get_phase()/(2*M_PI) + 5*d_ampl/4) + d_offset; - } - else { - optr[i] = gr_complex(d_ampl*d_nco.get_phase()/(2*M_PI) + d_ampl/2, - d_ampl*d_nco.get_phase()/(2*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()/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*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 * 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 * 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 */ diff --git a/gr-analog/lib/squelch_base_cc_impl.cc b/gr-analog/lib/squelch_base_cc_impl.cc index b5c153558b..0873d81acc 100644 --- a/gr-analog/lib/squelch_base_cc_impl.cc +++ b/gr-analog/lib/squelch_base_cc_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2006,2012 Free Software Foundation, Inc. + * Copyright 2004,2006,2012,2018 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -26,6 +26,7 @@ #include "squelch_base_cc_impl.h" #include <gnuradio/io_signature.h> +#include <gnuradio/math.h> namespace gr { namespace analog { @@ -120,7 +121,7 @@ namespace gr { break; case ST_ATTACK: - d_envelope = 0.5-std::cos(M_PI*(++d_ramped)/d_ramp)/2.0; // FIXME: precalculate window for speed + d_envelope = 0.5-std::cos(GR_M_PI*(++d_ramped)/d_ramp)/2.0; // FIXME: precalculate window for speed if(d_ramped >= d_ramp) { // use >= in case d_ramp is set to lower value elsewhere d_state = ST_UNMUTED; d_tag_next_unmuted = true; @@ -129,7 +130,7 @@ namespace gr { break; case ST_DECAY: - d_envelope = 0.5-std::cos(M_PI*(--d_ramped)/d_ramp)/2.0; // FIXME: precalculate window for speed + d_envelope = 0.5-std::cos(GR_M_PI*(--d_ramped)/d_ramp)/2.0; // FIXME: precalculate window for speed if(d_ramped == 0.0) { d_state = ST_MUTED; add_item_tag(0, nitems_written(0) + j, d_eob_key, pmt::PMT_NIL); diff --git a/gr-analog/lib/squelch_base_ff_impl.cc b/gr-analog/lib/squelch_base_ff_impl.cc index ea2d29bd97..2f164be363 100644 --- a/gr-analog/lib/squelch_base_ff_impl.cc +++ b/gr-analog/lib/squelch_base_ff_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2006,2012 Free Software Foundation, Inc. + * Copyright 2004,2006,2012,2018 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -26,6 +26,7 @@ #include "squelch_base_ff_impl.h" #include <gnuradio/io_signature.h> +#include <gnuradio/math.h> #include <pmt/pmt.h> namespace gr { @@ -120,7 +121,7 @@ namespace gr { case ST_ATTACK: // FIXME: precalculate window for speed - d_envelope = 0.5-std::cos(M_PI*(++d_ramped)/d_ramp)/2.0; + d_envelope = 0.5-std::cos(GR_M_PI*(++d_ramped)/d_ramp)/2.0; // use >= in case d_ramp is set to lower value elsewhere if(d_ramped >= d_ramp) { @@ -132,7 +133,7 @@ namespace gr { case ST_DECAY: // FIXME: precalculate window for speed - d_envelope = 0.5-std::cos(M_PI*(--d_ramped)/d_ramp)/2.0; + d_envelope = 0.5-std::cos(GR_M_PI*(--d_ramped)/d_ramp)/2.0; if(d_ramped == 0.0) { d_state = ST_MUTED; add_item_tag(0, nitems_written(0) + j, d_eob_key, pmt::PMT_NIL); |