24template <
typename SampleType>
39 m_initialNoiseLevelDb (initialNoiseLevelDb),
40 m_noiseLevelLinear (
static_cast<SampleType> (
decibelsToRatio (initialNoiseLevelDb
))),
41 m_randomSeed (randomSeed),
42 m_randomNumberGenerator (randomSeed)
46 void prepare (
double , size_t , size_t , size_t )
override {}
50 const bool symmetricalChannelLayout = input.getNumChannels() == output.getNumChannels();
51 const bool monoToMultiChannelLayout = input.getNumChannels() == 1 && output.getNumChannels() > 1;
53 if (! symmetricalChannelLayout && ! monoToMultiChannelLayout)
59 for (size_t outputChannel = 0; outputChannel < output.getNumChannels(); ++outputChannel)
61 const size_t inputChannel = symmetricalChannelLayout ? outputChannel : 0;
62 const SampleType* inputChannelData = input[inputChannel];
63 SampleType* outputChannelData = output[outputChannel];
65 if (channelsToProcess
[outputChannel
] ==
true)
67 for (size_t frame = 0; frame < input.getNumFrames(); ++frame)
68 outputChannelData[frame] = inputChannelData[frame] + m_noiseLevelLinear * m_uniformRealDistribution (m_randomNumberGenerator);
72 for (size_t frame = 0; frame < input.getNumFrames(); ++frame)
73 outputChannelData[frame] = inputChannelData[frame];
81 void setValue (
int paramId,
double value)
override
83 if (paramId !=
Params::noiseLevelDb)
91 m_randomNumberGenerator = std::mt19937 (m_randomSeed);
92 m_uniformRealDistribution.reset();
100 return numInputChannels == numOutputChannels
101 || (numInputChannels == 1 && numOutputChannels > 1);
104 virtual void represent (std::ostream& stream)
const override
112 << m_randomSeed <<
')';
126 double m_initialNoiseLevelDb;
127 SampleType m_noiseLevelLinear;
128 uint_fast32_t m_randomSeed;
130 std::mt19937 m_randomNumberGenerator;
131 std::uniform_real_distribution<SampleType> m_uniformRealDistribution {(SampleType) -1, (SampleType) 1};
Mixes additive white noise to the signal.
AdditiveNoise(double initialNoiseLevelDb=0.0, uint_fast32_t randomSeed=CLIConfig::getInstance().getRandomSeed())
Creates a DSP that mixes white noise to the signal.
void process(const AudioBuffer< SampleType > &input, AudioBuffer< SampleType > &output, const EnvelopeBuffers &, ChannelFlags channelsToProcess) override
Processes the audio.
void prepare(double, size_t, size_t, size_t) override
Prepare for processing.
void setValue(int paramId, double value) override
Sets additive noise level.
@ noiseLevelDb
Noise sample peak level in dB.
bool supportsEnvelopeFor(int) const override
No envelope support yet.
virtual void represent(std::ostream &stream) const override
Makes a text representation of this DSP effect for test failure outputs.
void reset() override
Resets to initial state.
bool supportsChannelLayout(size_t numInputChannels, size_t numOutputChannels) const override
Checks support for a specific channel layout.
Container for audio data.
A set of boolean flags mapped to each audio channel.
std::bitset< m_maxChannels >::reference operator[](size_t channel)
Access the flag value for a specific channel.
Thrown when an inappropriate value is encountered.
#define HART_DSP_COPYABLE(ClassName)
Implements a generic hart::DSP::copy() method.
#define HART_THROW_OR_RETURN_VOID(ExceptionType, message)
Throws an exception if HART_DO_NOT_THROW_EXCEPTIONS is set, prints a message and returns otherwise.
#define hassertfalse
Triggers a HartAssertException
std::ostream & dbPrecision(std::ostream &stream)
Sets number of decimal places for values in decibels.
static SampleType decibelsToRatio(SampleType valueDb)
Converts dB to linear value (ratio)
#define HART_DSP_DECLARE_ALIASES_FOR(ClassName)
Holds values set by the user via CLI interface.
uint_fast32_t getRandomSeed()
Gets random seed set by a "`--seed`/`-s`" argument.
static CLIConfig & getInstance()
Get the singleton instance.