HART  0.2.0
High level Audio Regression and Testing
Loading...
Searching...
No Matches
hart_whitenoise.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <memory>
5#include <random>
6#include <string>
7
9#include "signals/hart_signal.hpp"
10
11namespace hart
12{
13
14/// @brief Produces deterministic white noise
15/// @details Outputs a signal uniformly distrubuted between -1.0 and +1.0, thus peaking below 0dB
16/// @ingroup Signals
17template<typename SampleType>
19 public Signal<SampleType, WhiteNoise<SampleType>>
20{
21public:
22
23 /// @brief Creates a Signal that produces white noise
24 /// @param randomSeed Seed for the RNG
25 /// @details Two signals with the same seed are guaranteed to produce the identical audio
27 m_randomSeed (randomSeed)
28 {
29 reset();
30 }
31
32 bool supportsNumChannels (size_t /* numChannels */) const override { return true; };
33
34 void prepare (double /*sampleRateHz*/, size_t numOutputChannels, size_t /*maxBlockSizeFrames*/) override
35 {
36 this->setNumChannels (numOutputChannels);
37 }
38
39 void renderNextBlock (AudioBuffer<SampleType>& output) override
40 {
41 for (size_t frame = 0; frame < output.getNumFrames(); ++frame)
42 for (size_t channel = 0; channel < this->getNumChannels(); ++channel)
43 output[channel][frame] = m_uniformRealDistribution (m_randomNumberGenerator);
44 }
45
46 /// @copybrief Signal::reset()
47 /// @details After resetting, WhiteNoise is guaranteed to produce identical audio to the one produced after instantiation
48 void reset() override
49 {
50 m_randomNumberGenerator = std::mt19937 (m_randomSeed);
51 m_uniformRealDistribution.reset();
52 }
53
54 void represent (std::ostream& stream) const override
55 {
56 stream << "WhiteNoise (" << m_randomSeed << ")";
57 }
58
59private:
60 const uint_fast32_t m_randomSeed;
61 std::mt19937 m_randomNumberGenerator;
62 std::uniform_real_distribution<SampleType> m_uniformRealDistribution {(SampleType) -1, (SampleType) 1};
63};
64
66
67} // namespace hart
Base class for signals.
Produces deterministic white noise.
void renderNextBlock(AudioBuffer< SampleType > &output) override
Renders next block audio for the signal.
void prepare(double, size_t numOutputChannels, size_t) override
Prepare the signal for rendering.
void represent(std::ostream &stream) const override
Makes a text representation of this Signal for test failure outputs.
bool supportsNumChannels(size_t) const override
Tells the host whether this Signal is capable of generating audio for a certain amount of channels.
WhiteNoise(uint_fast32_t randomSeed=CLIConfig::getInstance().getRandomSeed())
Creates a Signal that produces white noise.
void reset() override
Resets the Signal to initial state.
#define HART_SIGNAL_DECLARE_ALIASES_FOR(ClassName)
uint_fast32_t getRandomSeed()
static CLIConfig & getInstance()