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

Base class for signals. More...

#include <hart_signal.hpp>

Inheritance diagram for Signal< SampleType >:

Public Member Functions

 Signal ()=default
 Default constructor.
 
 Signal (const Signal &other)
 Copies other signal.
 
 Signal (Signal &&other) noexcept
 Moves from other signal.
 
virtual ~Signal ()=default
 Destructor.
 
Signaloperator= (const Signal &other)
 Copies from other signal.
 
Signaloperator= (Signal &&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 cchannels.
 
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< Signal< SampleType > > copy () const =0
 Returns a smart pointer with a copy of this object.
 
virtual std::unique_ptr< Signal< 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.
 
SignalfollowedBy (const DSP< SampleType > &dsp)
 Adds a DSP effect to the end of signal's DSP chain by copying it.
 
SignalfollowedBy (std::unique_ptr< DSP< SampleType > > dsp)
 Adds a DSP effect to the end of signal's DSP chain by transfering a smart pointer.
 
template<typename DerivedDSP , typename = typename std::enable_if< std::is_base_of< DSP<SampleType>, typename std::decay<DerivedDSP>::type >::value >::type>
SignalfollowedBy (DerivedDSP &&dsp)
 Adds a DSP effect to the end of signal's DSP chain by moving it.
 
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.
 

Protected Member Functions

void setNumChannels (size_t numChannels)
 
size_t getNumChannels ()
 

Related Symbols

(Note that these are not member symbols.)

template<typename SampleType >
std::ostream & operator<< (std::ostream &stream, const Signal< SampleType > &signal)
 Prints readable text representation of the Signal object into the I/O stream.
 
template<typename SampleType , typename DerivedDSP , typename std::enable_if< std::is_base_of< DSP< SampleType >, typename std::decay< DerivedDSP >::type >::value >::type >
Signal< SampleType > & operator>> (Signal< SampleType > &signal, DerivedDSP &&dsp)
 Adds a DSP effect to the end of signal's DSP chain by moving it.
 
template<typename SampleType >
Signal< SampleType > & operator>> (Signal< SampleType > &signal, const DSP< SampleType > &dsp)
 Adds a DSP effect to the end of signal's DSP chain by copying it.
 
template<typename SampleType >
Signal< SampleType > && operator>> (Signal< SampleType > &&signal, const DSP< SampleType > &dsp)
 Adds a DSP effect to the end of signal's DSP chain by copying it.
 
template<typename SampleType >
Signal< SampleType > & operator>> (Signal< SampleType > &signal, std::unique_ptr< DSP< SampleType > > dsp)
 Adds a DSP effect to the end of signal's DSP chain by transfering it.
 
template<typename SampleType >
Signal< SampleType > && operator>> (Signal< SampleType > &&signal, std::unique_ptr< DSP< SampleType > > dsp)
 Adds a DSP effect to the end of signal's DSP chain by transfering it.
 

Detailed Description

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

Base class for signals.

Template Parameters
SampleTypeType of values that will be generated, typically float or double

Definition at line 24 of file hart_signal.hpp.

Constructor & Destructor Documentation

◆ Signal() [1/3]

template<typename SampleType >
Signal ( )
default

Default constructor.

◆ Signal() [2/3]

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

Copies other signal.

Definition at line 31 of file hart_signal.hpp.

◆ Signal() [3/3]

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

Moves from other signal.

Definition at line 44 of file hart_signal.hpp.

◆ ~Signal()

template<typename SampleType >
virtual ~Signal ( )
virtualdefault

Destructor.

Member Function Documentation

◆ operator=() [1/2]

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

Copies from other signal.

Definition at line 55 of file hart_signal.hpp.

◆ operator=() [2/2]

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

Moves from other signal.

Definition at line 73 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 cchannels.

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 WavFile< SampleType >, Silence< SampleType >, SineSweep< SampleType >, SineWave< SampleType >, and WhiteNoise< SampleType >.

Definition at line 91 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

Definition at line 98 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 WavFile< SampleType >, SineSweep< SampleType >, SineWave< SampleType >, WhiteNoise< 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

Implemented in 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 Silence< SampleType >, SineSweep< SampleType >, SineWave< SampleType >, WavFile< SampleType >, and WhiteNoise< SampleType >.

◆ copy()

template<typename SampleType >
virtual std::unique_ptr< Signal< SampleType > > copy ( ) const
pure virtual

Returns a smart pointer with a copy of this object.

Just put one of those two macros into your class body, and your copy() and move() are sorted:

Read their description, and choose one that fits your class. You can, of course, make your own implementation, but you're not supposed to, unless you're doing something obscure.

◆ move()

template<typename SampleType >
virtual std::unique_ptr< Signal< SampleType > > move ( )
pure virtual

Returns a smart pointer with a moved instance of this object.

Just pick a macro to define it - see description for copy() for details

◆ 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 SineSweep< SampleType >, SineWave< SampleType >, WavFile< SampleType >, and WhiteNoise< SampleType >.

◆ followedBy() [1/3]

template<typename SampleType >
Signal & followedBy ( const DSP< SampleType > &  dsp)
inline

Adds a DSP effect to the end of signal's DSP chain by copying it.

Note
For DSP object that do not support copying or moving, use version of this method that takes a unique_ptr instead
Parameters
dspA DSP effect instance

Definition at line 155 of file hart_signal.hpp.

◆ followedBy() [2/3]

template<typename SampleType >
Signal & followedBy ( std::unique_ptr< DSP< SampleType > >  dsp)
inline

Adds a DSP effect to the end of signal's DSP chain by transfering a smart pointer.

Note
For DSP object that do not support copying or moving, use version of this method that takes a unique_ptr instead
Parameters
dspA DSP effect instance

Definition at line 164 of file hart_signal.hpp.

◆ followedBy() [3/3]

template<typename SampleType >
template<typename DerivedDSP , typename = typename std::enable_if< std::is_base_of< DSP<SampleType>, typename std::decay<DerivedDSP>::type >::value >::type>
Signal & followedBy ( DerivedDSP &&  dsp)
inline

Adds a DSP effect to the end of signal's DSP chain by moving it.

Note
For DSP object that do not support copying or moving, use version of this method that takes a unique_ptr instead
Parameters
dspA DSP effect instance

Definition at line 184 of file hart_signal.hpp.

◆ 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 198 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 222 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 234 of file hart_signal.hpp.

◆ setNumChannels()

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

Definition at line 259 of file hart_signal.hpp.

◆ getNumChannels()

template<typename SampleType >
size_t getNumChannels ( )
inlineprotected

Definition at line 264 of file hart_signal.hpp.


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