summaryrefslogtreecommitdiff
path: root/gr-analog/lib
diff options
context:
space:
mode:
Diffstat (limited to 'gr-analog/lib')
-rw-r--r--gr-analog/lib/CMakeLists.txt7
-rw-r--r--gr-analog/lib/fastnoise_source_X_impl.cc.t144
-rw-r--r--gr-analog/lib/fastnoise_source_X_impl.h.t (renamed from gr-analog/lib/qa_rotator.h)42
-rw-r--r--gr-analog/lib/qa_analog.cc1
-rw-r--r--gr-analog/lib/qa_rotator.cc81
-rw-r--r--gr-analog/lib/sig_source_X_impl.cc.t2
6 files changed, 180 insertions, 97 deletions
diff --git a/gr-analog/lib/CMakeLists.txt b/gr-analog/lib/CMakeLists.txt
index e90bef5015..74169da4a2 100644
--- a/gr-analog/lib/CMakeLists.txt
+++ b/gr-analog/lib/CMakeLists.txt
@@ -35,6 +35,11 @@ include_directories(
link_directories(${Boost_LIBRARY_DIRS})
+if(ENABLE_GR_CTRLPORT)
+ ADD_DEFINITIONS(-DGR_CTRLPORT)
+ include_directories(${ICE_INCLUDE_DIR})
+endif(ENABLE_GR_CTRLPORT)
+
########################################################################
# generate helper scripts to expand templated files
########################################################################
@@ -100,6 +105,7 @@ endmacro(expand_cc)
# Invoke macro to generate various sources
########################################################################
expand_cc(noise_source_X_impl s i f c)
+expand_cc(fastnoise_source_X_impl s i f c)
expand_cc(sig_source_X_impl s i f c)
########################################################################
@@ -176,7 +182,6 @@ if(ENABLE_TESTING)
${CMAKE_CURRENT_SOURCE_DIR}/test_gr_analog.cc
${CMAKE_CURRENT_SOURCE_DIR}/qa_analog.cc
${CMAKE_CURRENT_SOURCE_DIR}/qa_sincos.cc
- ${CMAKE_CURRENT_SOURCE_DIR}/qa_rotator.cc
)
add_executable(test-gr-analog ${test_gr_analog_sources})
diff --git a/gr-analog/lib/fastnoise_source_X_impl.cc.t b/gr-analog/lib/fastnoise_source_X_impl.cc.t
new file mode 100644
index 0000000000..25ad8073aa
--- /dev/null
+++ b/gr-analog/lib/fastnoise_source_X_impl.cc.t
@@ -0,0 +1,144 @@
+/* -*- 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 <gr_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)
+ : gr_sync_block("@BASE_NAME@",
+ gr_make_io_signature(0, 0, 0),
+ gr_make_io_signature(1, 1, sizeof(@TYPE@))),
+ d_type(type),
+ d_ampl(ampl),
+ d_rng(seed)
+ {
+ d_samples.resize(samples);
+ generate();
+ }
+
+ @IMPL_NAME@::~@IMPL_NAME@()
+ {
+ }
+
+ void
+ @IMPL_NAME@::set_type(noise_type_t type)
+ {
+ gruel::scoped_lock l(d_setlock);
+ d_type = type;
+ generate();
+ }
+
+ void
+ @IMPL_NAME@::set_amplitude(float ampl)
+ {
+ gruel::scoped_lock l(d_setlock);
+ d_ampl = ampl;
+ 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)
+ {
+ gruel::scoped_lock l(d_setlock);
+
+ @TYPE@ *out = (@TYPE@*)output_items[0];
+
+ for(int i=0; i<noutput_items; i++) {
+#ifdef __USE_GNU
+ size_t idx = lrand48() % d_samples.size();
+#else
+ size_t idx = rand() % d_samples.size();
+#endif
+ out[i] = d_samples[idx];
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace analog */
+} /* namespace gr */
+
diff --git a/gr-analog/lib/qa_rotator.h b/gr-analog/lib/fastnoise_source_X_impl.h.t
index a22e41ec26..3c5dc106a2 100644
--- a/gr-analog/lib/qa_rotator.h
+++ b/gr-analog/lib/fastnoise_source_X_impl.h.t
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2008,2012 Free Software Foundation, Inc.
+ * Copyright 2013 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -20,26 +20,42 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef _QA_ANALOG_ROTATOR_H_
-#define _QA_ANALOG_ROTATOR_H_
+// @WARNING@
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/TestCase.h>
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include <analog/@BASE_NAME@.h>
+#include <gr_random.h>
namespace gr {
namespace analog {
- class qa_rotator : public CppUnit::TestCase
+ class @IMPL_NAME@ : public @BASE_NAME@
{
- CPPUNIT_TEST_SUITE(qa_rotator);
- CPPUNIT_TEST(t1);
- CPPUNIT_TEST_SUITE_END();
-
private:
- void t1();
+ noise_type_t d_type;
+ float d_ampl;
+ gr_random d_rng;
+ std::vector<@TYPE@> d_samples;
+
+ public:
+ @IMPL_NAME@(noise_type_t type, float ampl, long seed, long samples);
+ ~@IMPL_NAME@();
+
+ void set_type(noise_type_t type);
+ void set_amplitude(float ampl);
+ void generate();
+
+ noise_type_t type() const { return d_type; }
+ float amplitude() const { return d_ampl; }
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
};
- } /* namespace analog */
+ } /* namespace filter */
} /* namespace gr */
-#endif /* _QA_ANALOG_ROTATOR_H_ */
+#endif /* @GUARD_NAME@ */
diff --git a/gr-analog/lib/qa_analog.cc b/gr-analog/lib/qa_analog.cc
index c3d51863bd..f1e3a45e27 100644
--- a/gr-analog/lib/qa_analog.cc
+++ b/gr-analog/lib/qa_analog.cc
@@ -35,7 +35,6 @@ qa_gr_analog::suite()
CppUnit::TestSuite *s = new CppUnit::TestSuite("gr-analog");
s->addTest(gr::analog::qa_sincos::suite());
- s->addTest(gr::analog::qa_rotator::suite());
return s;
}
diff --git a/gr-analog/lib/qa_rotator.cc b/gr-analog/lib/qa_rotator.cc
deleted file mode 100644
index b722f32c43..0000000000
--- a/gr-analog/lib/qa_rotator.cc
+++ /dev/null
@@ -1,81 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2002,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 <gruel/attributes.h>
-#include <cppunit/TestAssert.h>
-#include <qa_rotator.h>
-#include <analog/rotator.h>
-#include <stdio.h>
-#include <cmath>
-#include <gr_expj.h>
-
-namespace gr {
- namespace analog {
-
- // error vector magnitude
- __GR_ATTR_UNUSED static float
- error_vector_mag(gr_complex a, gr_complex b)
- {
- return abs(a-b);
- }
-
- void
- qa_rotator::t1()
- {
- static const unsigned int N = 100000;
-
- rotator r;
-
- double phase_incr = 2*M_PI / 1003;
- double phase = 0;
-
- // Old code: We increment then return the rotated value, thus we
- // need to start one tick back
- // r.set_phase(gr_complex(1,0) * conj(gr_expj(phase_incr)));
-
- r.set_phase(gr_complex(1,0));
- r.set_phase_incr(gr_expj(phase_incr));
-
- for(unsigned i = 0; i < N; i++) {
- gr_complex expected = gr_expj(phase);
- gr_complex actual = r.rotate(gr_complex(1, 0));
-
-#if 0
- float evm = error_vector_mag(expected, actual);
- printf("[%6d] expected: (%8.6f, %8.6f) actual: (%8.6f, %8.6f) evm: %8.6f\n",
- i, expected.real(), expected.imag(), actual.real(), actual.imag(), evm);
-#endif
-
- CPPUNIT_ASSERT_COMPLEXES_EQUAL(expected, actual, 0.0001);
-
- phase += phase_incr;
- if(phase >= 2*M_PI)
- phase -= 2*M_PI;
- }
- }
-
- } /* namespace analog */
-} /* namespace gr */
diff --git a/gr-analog/lib/sig_source_X_impl.cc.t b/gr-analog/lib/sig_source_X_impl.cc.t
index 60653dc1bb..ad8b7e4b0c 100644
--- a/gr-analog/lib/sig_source_X_impl.cc.t
+++ b/gr-analog/lib/sig_source_X_impl.cc.t
@@ -211,7 +211,7 @@ namespace gr {
#endif
default:
- throw std::runtime_error("gr_sig_source: invalid waveform");
+ throw std::runtime_error("analog::sig_source: invalid waveform");
}
return noutput_items;