Line data Source code
1 : /** 2 : * \file WhiteNoiseGeneratorFilter.h 3 : */ 4 : 5 : #ifndef ATK_TOOLS_WHITENOISEGENERATORFILTER_H 6 : #define ATK_TOOLS_WHITENOISEGENERATORFILTER_H 7 : 8 : #include <ATK/Core/TypedBaseFilter.h> 9 : #include <ATK/Tools/config.h> 10 : 11 : #include <boost/random/mersenne_twister.hpp> 12 : #include <boost/random/uniform_real_distribution.hpp> 13 : 14 : namespace ATK 15 : { 16 : /// A uniform noise generator 17 : template<typename DataType_> 18 : class ATK_TOOLS_EXPORT WhiteNoiseGeneratorFilter final : public TypedBaseFilter<DataType_> 19 : { 20 : protected: 21 : /// Simplify parent calls 22 : using Parent = TypedBaseFilter<DataType_>; 23 : using typename Parent::DataType; 24 : using Parent::outputs; 25 : using Parent::output_sampling_rate; 26 : 27 : public: 28 : /// Constructor 29 : WhiteNoiseGeneratorFilter(); 30 : /// Destructor 31 4 : ~WhiteNoiseGeneratorFilter() override = default; 32 : 33 : /// Sets the output volume, doesn't update the cache 34 : void set_volume(DataType_ volume); 35 : /// Gets the output volume 36 : DataType_ get_volume() const; 37 : 38 : /// Sets the offset of the generated signal, doesn't update the cache 39 : void set_offset(DataType_ offset); 40 : /// Gets the offset 41 : DataType_ get_offset() const; 42 : 43 : protected: 44 : void process_impl(gsl::index size) const final; 45 : 46 : private: 47 : DataType_ volume{1}; 48 : DataType_ offset{0}; 49 : 50 : mutable boost::random::mt19937 gen; // Should use a random123 when they will be in Boost 51 : mutable boost::random::uniform_real_distribution<DataType_> dist{-1, 1}; 52 : }; 53 : } 54 : 55 : #endif