summaryrefslogtreecommitdiff
path: root/gr-analog/lib/fastnoise_source_impl.cc
diff options
context:
space:
mode:
authorMarcus Müller <mmueller@gnuradio.org>2019-08-07 21:45:12 +0200
committerMarcus Müller <marcus@hostalia.de>2019-08-09 23:04:28 +0200
commitf7bbf2c1d8d780294f3e016aff239ca35eb6516e (patch)
treee09ab6112e02b2215b2d59ac24d3d6ea2edac745 /gr-analog/lib/fastnoise_source_impl.cc
parent78431dc6941e3acc67c858277dfe4a0ed583643c (diff)
Tree: clang-format without the include sorting
Diffstat (limited to 'gr-analog/lib/fastnoise_source_impl.cc')
-rw-r--r--gr-analog/lib/fastnoise_source_impl.cc84
1 files changed, 51 insertions, 33 deletions
diff --git a/gr-analog/lib/fastnoise_source_impl.cc b/gr-analog/lib/fastnoise_source_impl.cc
index fdd0af11f4..580cf25e9a 100644
--- a/gr-analog/lib/fastnoise_source_impl.cc
+++ b/gr-analog/lib/fastnoise_source_impl.cc
@@ -36,39 +36,45 @@ 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));
+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() {
+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;
+ 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;
+ 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");
+ 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) {
+ : 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);
+ xoroshiro128p_seed(d_state, (uint64_t)seed);
generate();
}
@@ -81,31 +87,38 @@ 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_type(type),
+ d_ampl(ampl / sqrtf(2.0f))
+{
d_samples.resize(samples);
- xoroshiro128p_seed(d_state, (uint64_t) seed);
+ xoroshiro128p_seed(d_state, (uint64_t)seed);
generate();
}
template <class T>
-fastnoise_source_impl<T>::~fastnoise_source_impl() {}
+fastnoise_source_impl<T>::~fastnoise_source_impl()
+{
+}
template <class T>
-void fastnoise_source_impl<T>::set_type(noise_type_t type) {
+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) {
+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) {
+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();
@@ -113,7 +126,8 @@ void fastnoise_source_impl<gr_complex>::set_amplitude(float ampl) {
template <class T>
-void fastnoise_source_impl<T>::generate() {
+void fastnoise_source_impl<T>::generate()
+{
int noutput_items = d_samples.size();
switch (d_type) {
case GR_UNIFORM:
@@ -141,11 +155,11 @@ void fastnoise_source_impl<T>::generate() {
}
-
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_vector_void_star& output_items)
+{
gr::thread::scoped_lock l(this->d_setlock);
T* out = (T*)output_items[0];
@@ -158,29 +172,33 @@ int fastnoise_source_impl<T>::work(int noutput_items,
}
template <class T>
-T fastnoise_source_impl<T>::sample() {
+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() {
+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;
+ return (random_int & (1 << 23)) ? (-s) : s;
}
template <>
-gr_complex fastnoise_source_impl<gr_complex>::sample_unbiased() {
+gr_complex fastnoise_source_impl<gr_complex>::sample_unbiased()
+{
uint64_t random_int = xoroshiro128p_next(d_state);
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());
+ 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>& fastnoise_source_impl<T>::samples() const {
+const std::vector<T>& fastnoise_source_impl<T>::samples() const
+{
return d_samples;
}