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

Applies symmetrical hard clipping (no knee) to the signal. More...

#include <hart_hardclip.hpp>

Inheritance diagram for HardClip< SampleType >:

Public Types

enum  Params { thresholdDb }
 

Public Member Functions

 HardClip (double thresholdDb=0.0)
 Contructor.
 
void prepare (double, size_t, size_t, size_t) override
 Prepare for processing.
 
void process (const AudioBuffer< SampleType > &input, AudioBuffer< SampleType > &output, const EnvelopeBuffers &) override
 Processes the audio.
 
void reset () override
 Resets to initial state.
 
void setValue (int id, double value) override
 
double getValue (int id) const override
 
bool supportsChannelLayout (size_t numInputChannels, size_t numOutputChannels) const override
 
void represent (std::ostream &stream) const override
 Makes a text representation of this DSP effect for test failure outputs.
 
bool supportsEnvelopeFor (int) const override
 Tells whether this effect accepts automation envelopes for a particular parameter.
 
 HART_DSP_DEFINE_COPY_AND_MOVE (HardClip)
 
- Public Member Functions inherited from DSP< SampleType >
virtual bool supportsSampleRate (double) const
 Tells whether this effect supports given sample rate.
 
virtual std::unique_ptr< DSP< SampleType > > copy () const =0
 Returns a smart pointer with a copy of this object.
 
virtual std::unique_ptr< DSP< SampleType > > move ()=0
 Returns a smart pointer with a moved instance of this object.
 
virtual ~DSP ()=default
 Destructor.
 
 DSP ()=default
 Default constructor.
 
 DSP (const DSP &other)
 Copies from another DSP effect instance.
 
 DSP (DSP &&other) noexcept
 Move constructor.
 
DSPoperator= (const DSP &other)
 Copies from another DSP effect instance.
 
DSPoperator= (DSP &&other) noexcept
 Move assignment.
 
DSPwithEnvelope (int paramId, Envelope &&envelope)
 Adds envelope to a specific parameter by moving it.
 
DSPwithEnvelope (int paramId, const Envelope &envelope)
 Adds envelope to a specific parameter by copying it.
 
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 processWithEnvelopes (const AudioBuffer< SampleType > &input, AudioBuffer< SampleType > &output)
 Renders all the automation envelopes and processes the audio.
 

Additional Inherited Members

Detailed Description

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

Applies symmetrical hard clipping (no knee) to the signal.

Signal will never go above the threshold. Signal that doesn't peak above the threshold is guaranteed to be identical to the input signal.

Definition at line 17 of file hart_hardclip.hpp.

Member Enumeration Documentation

◆ Params

Enumerator
thresholdDb 

Threshold in decibels.

Definition at line 21 of file hart_hardclip.hpp.

Constructor & Destructor Documentation

◆ HardClip()

template<typename SampleType >
HardClip ( double  thresholdDb = 0.0)
inline

Contructor.

Parameters
thresholdDbFixed threshold in decibels, above which the signal will be symmetrically hard-clipped

Definition at line 28 of file hart_hardclip.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 DSP< SampleType >.

Definition at line 34 of file hart_hardclip.hpp.

◆ process()

template<typename SampleType >
void process ( const AudioBuffer< SampleType > &  input,
AudioBuffer< SampleType > &  output,
const EnvelopeBuffers envelopeBuffers 
)
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().

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

Implements DSP< SampleType >.

Definition at line 36 of file hart_hardclip.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

Implements DSP< SampleType >.

Definition at line 50 of file hart_hardclip.hpp.

◆ setValue()

template<typename SampleType >
void setValue ( int  id,
double  value 
)
inlineoverridevirtual
Parameters
idOnly HardClip::thresholdDb is accepted
valueThreshold in decibels

Implements DSP< SampleType >.

Definition at line 54 of file hart_hardclip.hpp.

◆ getValue()

template<typename SampleType >
double getValue ( int  id) const
inlineoverridevirtual
Parameters
idOnly HardClip::thresholdDb is accepted
Returns
Threshold in decibels

Implements DSP< SampleType >.

Definition at line 62 of file hart_hardclip.hpp.

◆ supportsChannelLayout()

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

Supports only n-to-n channel configurations

Implements DSP< SampleType >.

Definition at line 71 of file hart_hardclip.hpp.

◆ represent()

template<typename SampleType >
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 DSP< SampleType >.

Definition at line 76 of file hart_hardclip.hpp.

◆ supportsEnvelopeFor()

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

Tells whether this effect accepts automation envelopes for a particular parameter.

Parameters
paramIdSome ID that your subclass understands
Returns
true if your subclass can process automation for this parameter, false otherwise

Reimplemented from DSP< SampleType >.

Definition at line 81 of file hart_hardclip.hpp.

◆ HART_DSP_DEFINE_COPY_AND_MOVE()

template<typename SampleType >
HART_DSP_DEFINE_COPY_AND_MOVE ( HardClip< SampleType )

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