eDSP  0.0.1
A cross-platform DSP library written in C++.
white_noise_generator.hpp
Go to the documentation of this file.
1 /*
2  * eDSP, A cross-platform Digital Signal Processing library written in modern C++.
3  * Copyright (C) 2018 Mohammed Boujemaoui Boulaghmoudi, All rights reserved.
4  *
5  * This program is free software: you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the Free
7  * Software Foundation, either version 3 of the License, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along width
16  * this program. If not, see <http://www.gnu.org/licenses/>
17  *
18  * File: white_noise.hpp
19  * Author: Mohammed Boujemaoui
20  * Date: 31/7/2018
21  */
22 #ifndef EDSP_WHITE_NOISE_HPP
23 #define EDSP_WHITE_NOISE_HPP
24 
25 #include <random>
26 #include <chrono>
27 
28 namespace edsp { namespace random {
29 
34  template <typename T, typename Engine = std::mt19937>
36  using value_type = T;
37 
42  generator_(Engine(static_cast<std::size_t>(std::chrono::system_clock::now().time_since_epoch().count()))),
43  distribution_(std::uniform_int_distribution<T>(min, max)) {}
44 
50  return static_cast<value_type>(distribution_(generator_));
51  }
52 
53  private:
54  Engine generator_;
55  std::uniform_int_distribution<T> distribution_;
56  };
57 
58 }} // namespace edsp::random
59 
60 #endif // EDSP_WHITE_NOISE_HPP
constexpr meta::value_type_t< ForwardIt > max(ForwardIt first, ForwardIt last)
Computes the maximum value of the range [first, last)
Definition: max.hpp:38
This class implements a white noise generator.
Definition: white_noise_generator.hpp:35
white_noise_generator(value_type min, value_type max)
Creates a white noise sequence generator.
Definition: white_noise_generator.hpp:41
T value_type
Definition: white_noise_generator.hpp:36
value_type operator()()
Generates a random number following the noise distribution.
Definition: white_noise_generator.hpp:49
constexpr meta::value_type_t< ForwardIt > min(ForwardIt first, ForwardIt last)
Computes the minimum value of the range [first, last)
Definition: min.hpp:38
Definition: amplifier.hpp:29