eDSP  0.0.1
A cross-platform DSP library written in C++.
pink_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: pink_noise.hpp
19  * Author: Mohammed Boujemaoui
20  * Date: 31/7/2018
21  */
22 #ifndef EDSP_PINK_NOISE_HPP
23 #define EDSP_PINK_NOISE_HPP
24 
26 
27 namespace edsp { namespace random {
28 
33  template <typename T, typename Engine = std::mt19937>
35  using value_type = T;
36 
41  generator_(white_noise_generator<value_type>(min, max)) {}
42 
48  value_type white = generator_();
49  b0 = 0.99886 * b0 + white * 0.0555179;
50  b1 = 0.99332 * b1 + white * 0.0750759;
51  b2 = 0.96900 * b2 + white * 0.1538520;
52  b3 = 0.86650 * b3 + white * 0.3104856;
53  b4 = 0.55000 * b4 + white * 0.5329522;
54  b5 = -0.7616 * b5 - white * 0.0168980;
55  value_type output = (b0 + b1 + b2 + b3 + b4 + b5 + b6 + white * 0.5362) * 0.11;
56  b6 = white * 0.115926;
57  return output;
58  }
59 
60  private:
61  value_type b0{0};
62  value_type b1{0};
63  value_type b2{0};
64  value_type b3{0};
65  value_type b4{0};
66  value_type b5{0};
67  value_type b6{0};
69  };
70 
71 }} // namespace edsp::random
72 
73 #endif // EDSP_PINK_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
T value_type
Definition: pink_noise_generator.hpp:35
This class implements a white noise generator.
Definition: white_noise_generator.hpp:35
pink_noise_generator(value_type min, value_type max)
Creates a pink noise sequence generator.
Definition: pink_noise_generator.hpp:40
logger & white(logger &stream)
Updates the logger output color to white.
Definition: logger.hpp:362
This class implements a pink noise generator.
Definition: pink_noise_generator.hpp:34
value_type operator()()
Generates a random number following the noise distribution.
Definition: pink_noise_generator.hpp:47
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