HART  0.2.0
High level Audio Regression and Testing
Loading...
Searching...
No Matches
AdditiveNoise< SampleType > Class Template Reference

Mixes additive white noise to the signal. More...

#include <hart_additive_noise.hpp>

Inheritance diagram for AdditiveNoise< SampleType >:

Public Types

enum  Params { noiseLevelDb }
 

Public Member Functions

 AdditiveNoise (double initialNoiseLevelDb=0.0, uint_fast32_t randomSeed=CLIConfig::getInstance().getRandomSeed())
 Creates a DSP that mixes white noise to the signal.
 
void prepare (double, size_t, size_t, size_t) override
 Prepare for processing.
 
void process (const AudioBuffer< SampleType > &input, AudioBuffer< SampleType > &output, const EnvelopeBuffers &, ChannelFlags channelsToProcess) override
 Processes the audio.
 
void setValue (int paramId, double value) override
 Sets additive noise level.
 
void reset () override
 Resets to initial state.
 
bool supportsChannelLayout (size_t numInputChannels, size_t numOutputChannels) const override
 Checks support for a specific channel layout.
 
virtual void represent (std::ostream &stream) const override
 Makes a text representation of this DSP effect for test failure outputs.
 
bool supportsEnvelopeFor (int) const override
 No envelope support yet.
 
 HART_DSP_COPYABLE (AdditiveNoise)
 
- Public Member Functions inherited from DSP< SampleType, AdditiveNoise< SampleType > >
AdditiveNoise< SampleType > & withEnvelope (int paramId, Envelope &&envelope) &
 Adds envelope to a specific parameter by moving it.
 
AdditiveNoise< SampleType > && withEnvelope (int paramId, Envelope &&envelope) &&
 Adds envelope to a specific parameter by moving it.
 
AdditiveNoise< SampleType > & withEnvelope (int paramId, const Envelope &envelope) &
 Adds envelope to a specific parameter by copying it.
 
AdditiveNoise< SampleType > && withEnvelope (int paramId, const Envelope &envelope) &&
 Adds envelope to a specific parameter by copying it.
 
virtual std::unique_ptr< DSPBase< SampleType > > move () override
 Returns a smart pointer with a moved instance of this object.
 
AdditiveNoise< SampleType > & atChannels (std::initializer_list< size_t > channelsToProcess) &
 Makes this DSP process only specific channels, and ignore the rest.
 
AdditiveNoise< SampleType > && atChannels (std::initializer_list< size_t > channelsToProcess) &&
 Makes this DSP process only specific channels, and ignore the rest.
 
AdditiveNoise< SampleType > & atChannel (size_t channelToProcess) &
 Makes this DSP process only specific channels, and bypass the rest.
 
AdditiveNoise< SampleType > && atChannel (size_t channelToProcess) &&
 Makes this DSP process only specific channels, and bypass the rest.
 
AdditiveNoise< SampleType > & atAllChannels () &
 Makes this DSP apply to all channels.
 
AdditiveNoise< SampleType > && atAllChannels () &&
 Makes this DSP apply to all channels.
 
AdditiveNoise< SampleType > & atAllChannelsExcept (std::initializer_list< size_t > channelsToSkip) &
 Makes this DSP process only specific channels, and bypass the rest.
 
AdditiveNoise< SampleType > && atAllChannelsExcept (std::initializer_list< size_t > channelsToSkip) &&
 Makes this DSP process only specific channels, and bypass the rest.
 
- Public Member Functions inherited from DSPBase< SampleType >
virtual double getValue (int) const
 Retrieves DSP value.
 
virtual bool supportsSampleRate (double) const
 Tells whether this effect supports given sample rate.
 
virtual std::unique_ptr< DSPBase< SampleType > > copy () const
 Returns a smart pointer with a copy of this object.
 
virtual ~DSPBase ()=default
 Destructor.
 
 DSPBase ()=default
 Default constructor.
 
 DSPBase (const DSPBase &other)
 Copies from another DSP effect instance.
 
 DSPBase (DSPBase &&other) noexcept
 Move constructor.
 
DSPBaseoperator= (const DSPBase &other)
 Copies from another DSP effect instance.
 
DSPBaseoperator= (DSPBase &&other) noexcept
 Move assignment.
 
bool hasEnvelopeFor (int paramId)
 Checks if there's an automation envelope attached to a specific parameter.
 
void prepareWithEnvelopes (double sampleRateHz, size_t numInputChannels, size_t numOutputChannels, size_t maxBlockSizeFrames)
 Prepares all the attached envelopes and the effect itself for processing.
 
void resetWithEnvelopes ()
 Resets the DSP instance, and all associated Envelopes.
 
ChannelFlags getChannelsToProcess ()
 Returns a structure indicating which channels should be processed by this DSP.
 
void processWithEnvelopes (const AudioBuffer< SampleType > &input, AudioBuffer< SampleType > &output)
 Renders all the automation envelopes and processes the audio.
 
void representWithActiveChannels (std::ostream &stream) const
 Makes a text representation of this DSP with optional "atChannels" appendix.
 

Additional Inherited Members

- Protected Attributes inherited from DSPBase< SampleType >
std::unordered_map< int, std::unique_ptr< Envelope > > m_envelopes
 
ChannelFlags m_channelsToProcess {true}
 

Detailed Description

template<typename SampleType>
class hart::AdditiveNoise< SampleType >

Mixes additive white noise to the signal.

Can operate either in symmetricall channel configurations, i.e. same number of inputs and outputs, or mono input to many outputs. Either way, each output channel with get its own noise realization. As anything in HART, the noise is deterministic, and can be controlled using a custom seed, either by specifying one as CLI argument, or by supplying one to the ctor directly. Repeated renders with the same seed produce bit-identical noise.

Definition at line 25 of file hart_additive_noise.hpp.

Member Enumeration Documentation

◆ Params

template<typename SampleType >
enum Params
Enumerator
noiseLevelDb 

Noise sample peak level in dB.

Definition at line 29 of file hart_additive_noise.hpp.

Constructor & Destructor Documentation

◆ AdditiveNoise()

template<typename SampleType >
AdditiveNoise ( double  initialNoiseLevelDb = 0.0,
uint_fast32_t  randomSeed = CLIConfig::getInstance().getRandomSeed() 
)
inline

Creates a DSP that mixes white noise to the signal.

Parameters
initialNoiseLevelDbNoise sample peak level in dB (prior to mixing to the signal). Can be overridden at a later point by calling setValue() with a Param::noiseLevelDb argument.
randomSeedSeed for noise generation.

Definition at line 38 of file hart_additive_noise.hpp.

Member Function Documentation

◆ prepare()

template<typename SampleType >
void prepare ( double  sampleRateHz,
size_t  numInputChannels,
size_t  numOutputChannels,
size_t  maxBlockSizeFrames 
)
inlineoverridevirtual

Prepare for processing.

In real-time DSP, such methods are usually used for allocating memory and other non-realtime-safe and heavyweight operations. But keep in mind that that HART does not do real-time processing, so this merely follows common real-time DSP design conventions, where non-realtime operations are done in a separate callback like this one. This method is guaranteed to be called after supportsChannelLayout() and supportsSampleRate(), but before process(). It is guaranteed that the number of input and output channels obeys supportsChannelLayout() and supportsSampleRate() preferences. It is guaranteed that all subsequent process() calls will be in line with the arguments received in this callback.

Parameters
sampleRateHzsample rate at which the audio should be interpreted and processed
numInputChannelsNumber of input channels
numOutputChannelsNumber of output channels
maxBlockSizeFramesMaximum block size in frames (samples)

Implements DSPBase< SampleType >.

Definition at line 46 of file hart_additive_noise.hpp.

◆ process()

template<typename SampleType >
void process ( const AudioBuffer< SampleType > &  input,
AudioBuffer< SampleType > &  output,
const EnvelopeBuffers envelopeBuffers,
ChannelFlags  channelsToProcess 
)
inlineoverridevirtual

Processes the audio.

Depending on circumstances, this callback will either be called once to process an entire piece of audio from start to finish, or called repeatedly, one block at a time (see AudioTestBuilder::withBlockSize()). All audio blocks except the last one are guaranteed to be equal to maxBlockSizeFrames set in prepare() callback. It is guaranteed that input and output buffers are equal in length in frames (samples) to each, but they might have different number of channels. Use supportsChannelLayout() to indicate whether the effect supports a specific i/o configuration or not, as it will be called before prepare(). It is guaranteed that envelopeBuffers will only contain the values for all attached envelopes for this instance of DSP effect, and will not contain any data (including key with empty item) if there's no envelope attached to a specific parameter ID in this effects's instance. It will never contain envelopes for IDs that get rejected by supportsEnvelopeFor(). Each vector in the envelopeBuffers map is guaranteed to be at least as large as input (and output) block. For partial blocks, only the first input.getNumFrames() elements contain valid data for the current block; the rest may be stale or uninitialized. DSP implementations are expected to ignore values beyond that index range.

Note
This method may be called in a replacing manner, i. e. input and output may be references to the same object.
Warning
Remember that the very last block of audio is almost always smaller than the block size set in prepare(), so be careful with buffer bounds.
Note
Note that this method does not have to be real-time safe, as all rendering always happens offline. Also note that, unlike real-time audio applications, this method is called on the same thread as all others like prepare().
Parameters
inputInput audio block
outputOutput audio block
envelopeBuffersEnvelope values for this block, see EnvelopeBuffers
channelsToProcessChannels that need processing. Process channels that are marked true, bypass ones marked false.

Implements DSPBase< SampleType >.

Definition at line 48 of file hart_additive_noise.hpp.

◆ setValue()

template<typename SampleType >
void setValue ( int  paramId,
double  value 
)
inlineoverridevirtual

Sets additive noise level.

Parameters
idOnly Param::noiseLevelDb is accepted
valueNoise sample peak level in dB (prior to mixing to the signal).

Implements DSPBase< SampleType >.

Definition at line 81 of file hart_additive_noise.hpp.

◆ reset()

template<typename SampleType >
void reset ( )
inlineoverridevirtual

Resets to initial state.

Ideally should be implemented in a way that audio produced after resetting is identical to audio produced after instantiation

Reimplemented from DSPBase< SampleType >.

Definition at line 89 of file hart_additive_noise.hpp.

◆ supportsChannelLayout()

template<typename SampleType >
bool supportsChannelLayout ( size_t  numInputChannels,
size_t  numOutputChannels 
) const
inlineoverridevirtual

Checks support for a specific channel layout.

Can operate either in symmetrical channel configurations, i.e. same number of inputs and outputs, or mono input to many outputs.

Implements DSPBase< SampleType >.

Definition at line 98 of file hart_additive_noise.hpp.

◆ represent()

template<typename SampleType >
virtual void represent ( std::ostream &  stream) const
inlineoverridevirtual

Makes a text representation of this DSP effect for test failure outputs.

It is strongly encouraged to follow python's repr() conventions for returned text - basically, put something like "MyClass(value1, value2)" (with no quotes) into the stream whenever possible, or "<Readable info in angled brackets>" otherwise. Also, use built-in stream manipulators like dbPrecision wherever applicable. Use HART_DEFINE_GENERIC_REPRESENT() to get a basic implementation for this method.

Parameters
[out]streamOutput stream to write to

Implements DSPBase< SampleType >.

Definition at line 104 of file hart_additive_noise.hpp.

◆ supportsEnvelopeFor()

template<typename SampleType >
bool supportsEnvelopeFor ( int  ) const
inlineoverridevirtual

No envelope support yet.

Note
Envelope support can be implemented easily enough, but only when there's a good reason to have it. Keeping things simple for now.

Reimplemented from DSPBase< SampleType >.

Definition at line 118 of file hart_additive_noise.hpp.

◆ HART_DSP_COPYABLE()

template<typename SampleType >
HART_DSP_COPYABLE ( AdditiveNoise< SampleType >  )

The documentation for this class was generated from the following file: