From c31f52882a7eefda683cec42e65a95fd2127f780 Mon Sep 17 00:00:00 2001 From: Marcus Müller <mueller@kit.edu> Date: Fri, 16 Feb 2018 18:05:52 +0100 Subject: Converted fastnoise_source from rand() to xoroshiro128+ This solves the issue with libc rand() relying on global (not thread-local!) state and thus not being suited for multithreaded applications. This fixes #1542. --- gr-analog/lib/fastnoise_source_X_impl.h.t | 1 + 1 file changed, 1 insertion(+) (limited to 'gr-analog/lib/fastnoise_source_X_impl.h.t') diff --git a/gr-analog/lib/fastnoise_source_X_impl.h.t b/gr-analog/lib/fastnoise_source_X_impl.h.t index 8ad1e4f8fe..5bea010e62 100644 --- a/gr-analog/lib/fastnoise_source_X_impl.h.t +++ b/gr-analog/lib/fastnoise_source_X_impl.h.t @@ -38,6 +38,7 @@ namespace gr { float d_ampl; gr::random d_rng; std::vector<@TYPE@> d_samples; + uint64_t d_state[2]; public: @IMPL_NAME@(noise_type_t type, float ampl, long seed, long samples); -- cgit v1.2.3 From 57a92af4e9f4b5eba42a00749b0936d06a2779b4 Mon Sep 17 00:00:00 2001 From: Andrej Rode <mail@andrejro.de> Date: Mon, 19 Mar 2018 23:32:52 +0100 Subject: analog: improve fastnoise qa --- .../include/gnuradio/analog/fastnoise_source_X.h.t | 3 +++ gr-analog/lib/fastnoise_source_X_impl.cc.t | 4 ++++ gr-analog/lib/fastnoise_source_X_impl.h.t | 1 + gr-analog/python/analog/qa_fastnoise.py | 22 +++++++++++++++++++++- 4 files changed, 29 insertions(+), 1 deletion(-) (limited to 'gr-analog/lib/fastnoise_source_X_impl.h.t') diff --git a/gr-analog/include/gnuradio/analog/fastnoise_source_X.h.t b/gr-analog/include/gnuradio/analog/fastnoise_source_X.h.t index 850633979c..f588299604 100644 --- a/gr-analog/include/gnuradio/analog/fastnoise_source_X.h.t +++ b/gr-analog/include/gnuradio/analog/fastnoise_source_X.h.t @@ -29,6 +29,8 @@ #include <gnuradio/analog/noise_type.h> #include <gnuradio/sync_block.h> +#include <vector> + namespace gr { namespace analog { @@ -62,6 +64,7 @@ namespace gr { long seed = 0, long samples=1024*16); virtual @TYPE@ sample() = 0; virtual @TYPE@ sample_unbiased() = 0; + virtual const std::vector<@TYPE@>& samples() const = 0; /*! * Set the noise type. Nominally from the diff --git a/gr-analog/lib/fastnoise_source_X_impl.cc.t b/gr-analog/lib/fastnoise_source_X_impl.cc.t index 9283f11733..72c6cb0582 100644 --- a/gr-analog/lib/fastnoise_source_X_impl.cc.t +++ b/gr-analog/lib/fastnoise_source_X_impl.cc.t @@ -163,5 +163,9 @@ namespace gr { #endif } + const std::vector<@TYPE@>& @IMPL_NAME@::samples() const + { + return d_samples; + } } /* namespace analog */ } /* namespace gr */ diff --git a/gr-analog/lib/fastnoise_source_X_impl.h.t b/gr-analog/lib/fastnoise_source_X_impl.h.t index 5bea010e62..ef0465729d 100644 --- a/gr-analog/lib/fastnoise_source_X_impl.h.t +++ b/gr-analog/lib/fastnoise_source_X_impl.h.t @@ -50,6 +50,7 @@ namespace gr { 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; } diff --git a/gr-analog/python/analog/qa_fastnoise.py b/gr-analog/python/analog/qa_fastnoise.py index a7730ffcb1..f712d66ca7 100644 --- a/gr-analog/python/analog/qa_fastnoise.py +++ b/gr-analog/python/analog/qa_fastnoise.py @@ -30,7 +30,7 @@ class test_fastnoise_source(gr_unittest.TestCase): self.num = 2**22 self.num_items = 10**6 - self.default_args = {"samples": self.num, "seed": int(43), "ampl": 1} + self.default_args = {"samples": self.num, "seed": 43, "ampl": 1} def tearDown (self): pass @@ -115,5 +115,25 @@ class test_fastnoise_source(gr_unittest.TestCase): self.assertTrue(numpy.array_equal(data1, data2)) + def test_003_real_uniform_pool(self): + src = analog.fastnoise_source_f(type=analog.GR_UNIFORM, **self.default_args) + src2 = analog.fastnoise_source_f(type=analog.GR_UNIFORM, **self.default_args) + self.assertTrue(numpy.array_equal(numpy.array(src.samples()), numpy.array(src2.samples()))) + def test_003_real_gaussian_pool(self): + src = analog.fastnoise_source_f(type=analog.GR_GAUSSIAN, **self.default_args) + src2 = analog.fastnoise_source_f(type=analog.GR_GAUSSIAN, **self.default_args) + self.assertTrue(numpy.array_equal(numpy.array(src.samples()), numpy.array(src2.samples()))) + def test_003_cmplx_gaussian_pool(self): + src = analog.fastnoise_source_c(type=analog.GR_GAUSSIAN, **self.default_args) + src2 = analog.fastnoise_source_c(type=analog.GR_GAUSSIAN, **self.default_args) + self.assertTrue(numpy.array_equal(numpy.array(src.samples()), numpy.array(src2.samples()))) + def test_003_cmplx_uniform_pool(self): + src = analog.fastnoise_source_c(type=analog.GR_UNIFORM, **self.default_args) + src2 = analog.fastnoise_source_c(type=analog.GR_UNIFORM, **self.default_args) + self.assertTrue(numpy.array_equal(numpy.array(src.samples()), numpy.array(src2.samples()))) + def test_003_real_laplacian_pool(self): + src = analog.fastnoise_source_f(type=analog.GR_LAPLACIAN, **self.default_args) + src2 = analog.fastnoise_source_f(type=analog.GR_LAPLACIAN, **self.default_args) + self.assertTrue(numpy.array_equal(numpy.array(src.samples()), numpy.array(src2.samples()))) if __name__ == '__main__': gr_unittest.run(test_fastnoise_source, "test_fastnoise_source.xml") -- cgit v1.2.3