diff options
Diffstat (limited to 'gr-analog/lib')
-rw-r--r-- | gr-analog/lib/CMakeLists.txt | 27 | ||||
-rw-r--r-- | gr-analog/lib/fastnoise_source_impl.cc | 36 | ||||
-rw-r--r-- | gr-analog/lib/fastnoise_source_impl.h | 3 | ||||
-rw-r--r-- | gr-analog/lib/fmdet_cf_impl.cc | 39 | ||||
-rw-r--r-- | gr-analog/lib/qa_analog.cc | 36 | ||||
-rw-r--r-- | gr-analog/lib/qa_analog.h | 38 | ||||
-rw-r--r-- | gr-analog/lib/test_gr_analog.cc | 48 |
7 files changed, 42 insertions, 185 deletions
diff --git a/gr-analog/lib/CMakeLists.txt b/gr-analog/lib/CMakeLists.txt index eeb287db05..9a41d12fe7 100644 --- a/gr-analog/lib/CMakeLists.txt +++ b/gr-analog/lib/CMakeLists.txt @@ -125,25 +125,18 @@ endif(ENABLE_STATIC_LIBS) if(ENABLE_TESTING) include(GrTest) - include_directories(${CPPUNIT_INCLUDE_DIRS}) - link_directories(${CPPUNIT_LIBRARY_DIRS}) + include_directories( + ${GR_ANALOG_INCLUDE_DIRS} + ${GNURADIO_RUNTIME_INCLUDE_DIRS} + ) list(APPEND test_gr_analog_sources - ${CMAKE_CURRENT_SOURCE_DIR}/test_gr_analog.cc - ${CMAKE_CURRENT_SOURCE_DIR}/qa_analog.cc - ) - - add_executable(test-gr-analog ${test_gr_analog_sources}) - - target_link_libraries( - test-gr-analog - gnuradio-runtime - gnuradio-analog - ${Boost_LIBRARIES} - ${CPPUNIT_LIBRARIES} ) + list(APPEND GR_TEST_TARGET_DEPS gnuradio-analog) - list(APPEND GR_TEST_TARGET_DEPS gnuradio-analog gnuradio-filter gnuradio-fft) - - GR_ADD_TEST(test_gr_analog test-gr-analog) + foreach(qa_file ${test_gr_analog_sources}) + GR_ADD_CPP_TEST("analog_${qa_file}" + ${CMAKE_CURRENT_SOURCE_DIR}/${qa_file} + ) + endforeach(qa_file) endif(ENABLE_TESTING) diff --git a/gr-analog/lib/fastnoise_source_impl.cc b/gr-analog/lib/fastnoise_source_impl.cc index ef85586b98..9cdea4e50d 100644 --- a/gr-analog/lib/fastnoise_source_impl.cc +++ b/gr-analog/lib/fastnoise_source_impl.cc @@ -26,6 +26,7 @@ #endif #include "fastnoise_source_impl.h" +#include <gnuradio/xoroshiro128p.h> #include <gnuradio/io_signature.h> #include <stdexcept> @@ -64,8 +65,9 @@ fastnoise_source_impl<T>::fastnoise_source_impl(noise_type_t type, 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_type(type), d_ampl(ampl) { d_samples.resize(samples); + xoroshiro128p_seed(d_state, (uint64_t) seed); generate(); } @@ -78,8 +80,9 @@ fastnoise_source_impl<gr_complex>::fastnoise_source_impl(noise_type_t type, : 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_type(type), d_ampl(ampl / sqrtf(2.0f)) { d_samples.resize(samples); + xoroshiro128p_seed(d_state, (uint64_t) seed); generate(); } @@ -155,31 +158,28 @@ int fastnoise_source_impl<T>::work(int 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 + size_t idx = xoroshiro128p_next(d_state) % d_samples.size(); 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(); + 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() { - gr_complex s(sample()); - return gr_complex(FASTNOISE_RANDOM_SIGN * s.real(), FASTNOISE_RANDOM_SIGN * s.imag()); + 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; } diff --git a/gr-analog/lib/fastnoise_source_impl.h b/gr-analog/lib/fastnoise_source_impl.h index 2795b269dc..f40d39d5f1 100644 --- a/gr-analog/lib/fastnoise_source_impl.h +++ b/gr-analog/lib/fastnoise_source_impl.h @@ -26,6 +26,7 @@ #include <gnuradio/analog/fastnoise_source.h> #include <gnuradio/random.h> +#include <vector> namespace gr { namespace analog { @@ -38,6 +39,7 @@ template<class T> float d_ampl; gr::random d_rng; std::vector<T> d_samples; + uint64_t d_state[2]; public: fastnoise_source_impl(noise_type_t type, float ampl, long seed, long samples); @@ -45,6 +47,7 @@ template<class T> T sample(); T sample_unbiased(); + const std::vector<T>& samples() const; void set_type(noise_type_t type); void set_amplitude(float ampl); diff --git a/gr-analog/lib/fmdet_cf_impl.cc b/gr-analog/lib/fmdet_cf_impl.cc index 5151f027d4..fdd438f335 100644 --- a/gr-analog/lib/fmdet_cf_impl.cc +++ b/gr-analog/lib/fmdet_cf_impl.cc @@ -31,8 +31,6 @@ namespace gr { namespace analog { -#define M_TWOPI (2*GR_M_PI) - fmdet_cf::sptr fmdet_cf::make(float samplerate, float freq_low, float freq_high, float scl) @@ -46,26 +44,13 @@ namespace gr { : sync_block("fmdet_cf", io_signature::make(1, 1, sizeof(gr_complex)), io_signature::make(1, 1, sizeof(float))), - d_S1(0.1), d_S2(0.1), - d_S3(0.1), d_S4(0.1) + d_S1(0.1), d_S2(0.1), + d_S3(0.1), d_S4(0.1) { - //const float h[] = { 0.003118678733, -0.012139843428, 0.027270898036, - // -0.051318579352, 0.090406910552, -0.162926865366, - // 0.361885392563, 0.000000000000, -0.361885392563, - // 0.162926865366, -0.090406910552, 0.051318579352, - // -0.027270898036, 0.012139843428, -0.003118678733}; - - //std::vector<float> taps(15); - d_freq = 0; d_freqhi = freq_high; d_freqlo = freq_low; set_scale(scl); - - //for(int i = 0; i < 15; i++) { - //taps[i] = h[i]; - //} - // d_filter = gr_fir_util::create_gr_fir_ccf(taps); } fmdet_cf_impl::~fmdet_cf_impl() @@ -95,28 +80,26 @@ namespace gr { { const gr_complex *iptr = (gr_complex*)input_items[0]; float *optr = (float*)output_items[0]; - //const gr_complex *scaleiptr = (gr_complex*)input_items[0]; int size = noutput_items; gr_complex Sdot, S0; gr_complex S1=d_S1, S2=d_S2, S3=d_S3, S4=d_S4; - float d_8 = 8.0; while(size-- > 0) { - S0 = *iptr++; + S0 = *iptr++; - Sdot = d_scl * (-S0+d_8*S1-d_8*S2+S4); + Sdot = d_scl * (-S0 + 8.f*S1 - 8.f*S3 + S4); - d_freq = (S2.real()*Sdot.imag()-S2.imag()*Sdot.real()) / - (S2.real()*S2.real()+S2.imag()*S2.imag()); + d_freq = (S2.real()*Sdot.imag() - S2.imag()*Sdot.real()) / + (S2.real()*S2.real() + S2.imag()*S2.imag()); - S4 = S3; - S3 = S2; - S2 = S1; - S1 = S0; + S4 = S3; + S3 = S2; + S2 = S1; + S1 = S0; - *optr++ = d_freq-d_bias; + *optr++ = d_freq-d_bias; } d_S1 = S1; d_S2 = S2; diff --git a/gr-analog/lib/qa_analog.cc b/gr-analog/lib/qa_analog.cc deleted file mode 100644 index c7c975a3e5..0000000000 --- a/gr-analog/lib/qa_analog.cc +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 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. - */ - -/* - * This class gathers together all the test cases for the gr-analog - * directory into a single test suite. As you create new test cases, - * add them here. - */ - -#include <qa_analog.h> - -CppUnit::TestSuite * -qa_gr_analog::suite() -{ - CppUnit::TestSuite *s = new CppUnit::TestSuite("gr-analog"); - - return s; -} diff --git a/gr-analog/lib/qa_analog.h b/gr-analog/lib/qa_analog.h deleted file mode 100644 index cdb5c78b94..0000000000 --- a/gr-analog/lib/qa_analog.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 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. - */ - -#ifndef _QA_GR_ANALOG_H_ -#define _QA_GR_ANALOG_H_ - -#include <gnuradio/attributes.h> -#include <cppunit/TestSuite.h> - -//! collect all the tests for the gr-analog directory - -class __GR_ATTR_EXPORT qa_gr_analog { - public: - //! return suite of tests for all of gr-analog directory - static CppUnit::TestSuite *suite(); -}; - - -#endif /* _QA_GR_ANALOG_H_ */ diff --git a/gr-analog/lib/test_gr_analog.cc b/gr-analog/lib/test_gr_analog.cc deleted file mode 100644 index 228a99e347..0000000000 --- a/gr-analog/lib/test_gr_analog.cc +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <cppunit/TextTestRunner.h> -#include <cppunit/XmlOutputter.h> - -#include <gnuradio/unittests.h> -#include "qa_analog.h" -#include <iostream> -#include <fstream> - -int -main (int argc, char **argv) -{ - CppUnit::TextTestRunner runner; - std::ofstream xmlfile(get_unittest_path("gr_analog.xml").c_str()); - CppUnit::XmlOutputter *xmlout = new CppUnit::XmlOutputter(&runner.result(), xmlfile); - - runner.addTest(qa_gr_analog::suite()); - runner.setOutputter(xmlout); - - bool was_successful = runner.run("", false); - - return was_successful ? 0 : 1; -} |