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

Polymorphic base for all signals. More...

#include <hart_signal.hpp>

Inheritance diagram for SignalBase< SampleType >:

Public Member Functions

 SignalBase ()=default
 Default constructor.
 
 SignalBase (const SignalBase &other)
 Copies other signal.
 
 SignalBase (SignalBase &&other) noexcept
 Moves from other signal.
 
virtual ~SignalBase ()=default
 Destructor.
 
SignalBaseoperator= (const SignalBase &other)
 Copies from other signal.
 
SignalBaseoperator= (SignalBase &&other) noexcept
 Moves from other signal.
 
virtual bool supportsNumChannels (size_t) const
 Tells the host whether this Signal is capable of generating audio for a certain amount of channels.
 
virtual bool supportsSampleRate (double) const
 Tells whether this Signal supports given sample rate.
 
virtual void prepare (double sampleRateHz, size_t numOutputChannels, size_t maxBlockSizeFrames)=0
 Prepare the signal for rendering.
 
virtual void renderNextBlock (AudioBuffer< SampleType > &output)=0
 Renders next block audio for the signal.
 
virtual void reset ()=0
 Resets the Signal to initial state.
 
virtual std::unique_ptr< SignalBase< SampleType > > copy () const =0
 Returns a smart pointer with a copy of this object.
 
virtual std::unique_ptr< SignalBase< SampleType > > move ()=0
 Returns a smart pointer with a moved instance of this object.
 
virtual void represent (std::ostream &stream) const =0
 Makes a text representation of this Signal for test failure outputs.
 
void prepareWithDSPChain (double sampleRateHz, size_t numOutputChannels, size_t maxBlockSizeFrames)
 Prepares the signal and all attached effects in the DSP chain for rendering.
 
void renderNextBlockWithDSPChain (AudioBuffer< SampleType > &output)
 Renders next block audio for the signal and all the effects in the DSP chain.
 
virtual void resetWithDSPChain ()
 Resets to Signal and all the effects attached to its DSP chain to initial state.
 
size_t getDSPChainSize () const
 Returns the size of the DSP chain attached to the Signal.
 
DSPBase< SampleType > * getDSP (int index=-1) const
 Access a specific element in the DSP chain.
 
std::unique_ptr< DSPBase< SampleType > > popDSP (int index=-1)
 Extract a specific element in the DSP chain by removing it.
 

Protected Member Functions

void setNumChannels (size_t numChannels)
 
size_t getNumChannels ()
 

Protected Attributes

size_t m_numChannels = 1
 
double m_startTimestampSeconds = 0.0
 
std::vector< std::unique_ptr< DSPBase< SampleType > > > m_dspChain
 

Detailed Description

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

Polymorphic base for all signals.

Warning
This class exists only for type erasure and polymorphism. Do NOT inherit custom signals from this class directly. Inherit from hart::Signal instead.

Definition at line 27 of file hart_signal.hpp.

Constructor & Destructor Documentation

◆ SignalBase() [1/3]

template<typename SampleType >
SignalBase ( )
default

Default constructor.

◆ SignalBase() [2/3]

template<typename SampleType >
SignalBase ( const SignalBase< SampleType > &  other)
inline

Copies other signal.

Definition at line 34 of file hart_signal.hpp.

◆ SignalBase() [3/3]

template<typename SampleType >
SignalBase ( SignalBase< SampleType > &&  other)
inlinenoexcept

Moves from other signal.

Definition at line 65 of file hart_signal.hpp.

◆ ~SignalBase()

template<typename SampleType >
virtual ~SignalBase ( )
virtualdefault

Destructor.

Member Function Documentation

◆ operator=() [1/2]

template<typename SampleType >
SignalBase & operator= ( const SignalBase< SampleType > &  other)
inline

Copies from other signal.

Definition at line 78 of file hart_signal.hpp.

◆ operator=() [2/2]

template<typename SampleType >
SignalBase & operator= ( SignalBase< SampleType > &&  other)
inlinenoexcept

Moves from other signal.

Definition at line 116 of file hart_signal.hpp.

◆ supportsNumChannels()

template<typename SampleType >
virtual bool supportsNumChannels ( size_t  ) const
inlinevirtual

Tells the host whether this Signal is capable of generating audio for a certain amount of channels.

It is guaranteed that the signal will not receive unsupported number of channels in renderNextBlock(). This method is guaranteed to be called at least once before prepare()

Note
This method should only care about the Signal itself, and not the attached effects in DSP chain - they'll be queried separately
Parameters
numChannelsNumber of output channels that will need to be filled
Returns
true if signal is capable of filling this many channels with audio, false otherwise

Reimplemented in AudioBufferSignal< SampleType >, WavFile< SampleType >, Silence< SampleType >, SineSweep< SampleType >, SineWave< SampleType >, and WhiteNoise< SampleType >.

Definition at line 136 of file hart_signal.hpp.

◆ supportsSampleRate()

template<typename SampleType >
virtual bool supportsSampleRate ( double  ) const
inlinevirtual

Tells whether this Signal supports given sample rate.

It is guaranteed to be called before prepare()

Note
This method should only care about the Signal itself, and not the attached effects in DSP chain - they'll be queried separately
Parameters
sampleRateHzsample rate at which the audio should be generated
Returns
true if signal is capable of generating audio at a given sample rate, false otherwise

Reimplemented in AudioBufferSignal< SampleType >.

Definition at line 143 of file hart_signal.hpp.

◆ prepare()

template<typename SampleType >
virtual void prepare ( double  sampleRateHz,
size_t  numOutputChannels,
size_t  maxBlockSizeFrames 
)
pure virtual

Prepare the signal for rendering.

This method is guaranteed to be called after supportsNumChannels() and supportsSampleRate(), but before renderNextBlock(). It is guaranteed that numChannels obeys supportsNumChannels() preferences, same with sampleRateHz and supportsSampleRate(). It is guaranteed that all subsequent renderNextBlock() calls will be in line with the arguments received in this callback.

Parameters
sampleRateHzsample rate at which the audio should be generated
numOutputChannelsNumber of output channels to be filled
maxBlockSizeFramesMaximum block size in frames (samples)

Implemented in MixedSignal< SampleType >, AudioBufferSignal< SampleType >, SignalFunction< SampleType >, WavFile< SampleType >, Sawtooth< SampleType >, SineSweep< SampleType >, SineWave< SampleType >, WhiteNoise< SampleType >, Impulse< SampleType >, and Silence< SampleType >.

◆ renderNextBlock()

template<typename SampleType >
virtual void renderNextBlock ( AudioBuffer< SampleType > &  output)
pure virtual

Renders next block audio for the signal.

Depending on circumstances, this callback will either be called once to generate an entire piece of audio from start to finish, or called repeatedly, one block at a time. This method is guaranteed to be called strictly after prepare(), or not called at all. Number of channels and max block size are guaranteed to be in line with the ones set by prepare() callback. Assume sample rate to always be equal to the one received in the last prepare() callback. All audio blocks except the last one are guaranteed to be equal to maxBlockSizeFrames set in prepare() callback.

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
outputOutput audio block
Warning
Output audio buffer is not guaranteed to be pre-filled with zeros, it may contain junk data.

Implemented in AudioBufferSignal< SampleType >, Impulse< SampleType >, MixedSignal< SampleType >, Sawtooth< SampleType >, SignalFunction< SampleType >, Silence< SampleType >, SineSweep< SampleType >, SineWave< SampleType >, WavFile< SampleType >, and WhiteNoise< SampleType >.

◆ reset()

template<typename SampleType >
virtual void reset ( )
pure virtual

Resets the Signal to initial state.

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

Implemented in AudioBufferSignal< SampleType >, Impulse< SampleType >, MixedSignal< SampleType >, Sawtooth< SampleType >, SignalFunction< SampleType >, Silence< SampleType >, SineSweep< SampleType >, SineWave< SampleType >, WavFile< SampleType >, and WhiteNoise< SampleType >.

◆ copy()

◆ move()

◆ represent()

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

Makes a text representation of this Signal 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

Implemented in MixedSignal< SampleType >, AudioBufferSignal< SampleType >, Sawtooth< SampleType >, SignalFunction< SampleType >, SineSweep< SampleType >, SineWave< SampleType >, WavFile< SampleType >, and WhiteNoise< SampleType >.

◆ prepareWithDSPChain()

template<typename SampleType >
void prepareWithDSPChain ( double  sampleRateHz,
size_t  numOutputChannels,
size_t  maxBlockSizeFrames 
)
inline

Prepares the signal and all attached effects in the DSP chain for rendering.

This method is intended to be called by Signal hosts like AudioTestBuilder or Matcher. If you're making something that owns an instance of a Signal and needs it to generate audio, like a custom Matcher, you must call this method before calling renderNextBlockWithDSPChain(). You must also call supportsNumChannels() and supportsSampleRate() before calling this method.

Attention
If you're not making a custom host, you probably don't need to call this method.

Definition at line 197 of file hart_signal.hpp.

◆ renderNextBlockWithDSPChain()

template<typename SampleType >
void renderNextBlockWithDSPChain ( AudioBuffer< SampleType > &  output)
inline

Renders next block audio for the signal and all the effects in the DSP chain.

This method is intended to be called by Signal hosts like AudioTestBuilder or Matcher If you're making something that owns an instance of a Signal and needs it to generate audio, like a custom Matcher, you must call it after calling prepareWithDSPChain().

Attention
If you're not making a custom host, you probably don't need to call this method.

Definition at line 223 of file hart_signal.hpp.

◆ resetWithDSPChain()

template<typename SampleType >
virtual void resetWithDSPChain ( )
inlinevirtual

Resets to Signal and all the effects attached to its DSP chain to initial state.

This method is intended to be called by hosts like AudioTestBuilder or Matcher. If you're not making a custom host, you probably don't need this method.

Definition at line 235 of file hart_signal.hpp.

◆ getDSPChainSize()

template<typename SampleType >
size_t getDSPChainSize ( ) const
inline

Returns the size of the DSP chain attached to the Signal.

Returns
Number of elements in the DSP chain

Definition at line 257 of file hart_signal.hpp.

◆ getDSP()

template<typename SampleType >
DSPBase< SampleType > * getDSP ( int  index = -1) const
inline

Access a specific element in the DSP chain.

Parameters
indexIndex of the element. Can be negative. For non-negative values, it's a usual 0-based index. For negative values, it's counted from the end, e.g. "-1" is the last element, "-2" is the second to last etc.
Exceptions
hart::IndexErrorif the index is out of range
Returns
A pointer to the DSP instance

Definition at line 267 of file hart_signal.hpp.

◆ popDSP()

template<typename SampleType >
std::unique_ptr< DSPBase< SampleType > > popDSP ( int  index = -1)
inline

Extract a specific element in the DSP chain by removing it.

Parameters
indexIndex of the element. Can be negative. For non-negative values, it's a usual 0-based index. For negative values, it's counted from the end, e.g. "-1" is the last element, "-2" is the second to last etc.
Exceptions
hart::IndexErrorif the index is out of range
Returns
A smart pointer with the DSP instance

Definition at line 289 of file hart_signal.hpp.

◆ setNumChannels()

template<typename SampleType >
void setNumChannels ( size_t  numChannels)
inlineprotected

Definition at line 310 of file hart_signal.hpp.

◆ getNumChannels()

template<typename SampleType >
size_t getNumChannels ( )
inlineprotected

Definition at line 315 of file hart_signal.hpp.

Member Data Documentation

◆ m_numChannels

template<typename SampleType >
size_t m_numChannels = 1
protected

Definition at line 320 of file hart_signal.hpp.

◆ m_startTimestampSeconds

template<typename SampleType >
double m_startTimestampSeconds = 0.0
protected

Definition at line 321 of file hart_signal.hpp.

◆ m_dspChain

template<typename SampleType >
std::vector<std::unique_ptr<DSPBase<SampleType> > > m_dspChain
protected

Definition at line 322 of file hart_signal.hpp.


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