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

Produces audio from a wav file. More...

#include <hart_wavfile.hpp>

Inheritance diagram for WavFile< SampleType >:

Public Types

enum class  Loop { yes , no }
 

Public Member Functions

 WavFile (const std::string &filePath, Loop loop=Loop::no)
 Creates a Signal that produces audio from a wav file.
 
bool supportsNumChannels (size_t numChannels) const override
 Tells the host whether this Signal is capable of generating audio for a certain amount of cchannels.
 
void prepare (double sampleRateHz, size_t numOutputChannels, size_t) override
 Prepare the signal for rendering.
 
void renderNextBlock (AudioBuffer< SampleType > &output) override
 Renders next block audio for the signal.
 
void reset () override
 Resets the Signal to initial state.
 
void represent (std::ostream &stream) const override
 Makes a text representation of this Signal for test failure outputs.
 
 HART_SIGNAL_DEFINE_COPY_AND_MOVE (WavFile)
 
- Public Member Functions inherited from Signal< SampleType >
 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 supportsSampleRate (double) const
 Tells whether this Signal supports given sample rate.
 
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.
 
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.
 

Additional Inherited Members

- Protected Member Functions inherited from Signal< SampleType >
void setNumChannels (size_t numChannels)
 
size_t getNumChannels ()
 

Detailed Description

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

Produces audio from a wav file.

Original levels from the wav file are preserved

Definition at line 23 of file hart_wavfile.hpp.

Member Enumeration Documentation

◆ Loop

template<typename SampleType >
enum class Loop
strong
Enumerator
yes 
no 

Definition at line 27 of file hart_wavfile.hpp.

Constructor & Destructor Documentation

◆ WavFile()

template<typename SampleType >
WavFile ( const std::string &  filePath,
Loop  loop = Loop::no 
)
inline

Creates a Signal that produces audio from a wav file.

Parameters
filePathPath to a wav file Can be absolute or relative. If a relative path is used, it will resolve as relative to a data root path provided via respective CLI argument.
See also
HART_REQUIRES_DATA_PATH_ARG
Parameters
loopIndicates whether the signal should loop the audio or produce silence after wav file runs out of frames.

Definition at line 40 of file hart_wavfile.hpp.

Member Function Documentation

◆ supportsNumChannels()

template<typename SampleType >
bool supportsNumChannels ( size_t  numChannels) const
inlineoverridevirtual

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
Note
WavFile can only fill as much channels as there are in the wav file, or less. For instance, if the wav file is stereo, it can generate two channels (as they are), one channel (left, discarding right), but not three channels.

Reimplemented from Signal< SampleType >.

Definition at line 77 of file hart_wavfile.hpp.

◆ prepare()

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

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)

Implements Signal< SampleType >.

Definition at line 82 of file hart_wavfile.hpp.

◆ renderNextBlock()

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

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

Implements Signal< SampleType >.

Definition at line 92 of file hart_wavfile.hpp.

◆ reset()

template<typename SampleType >
void reset ( )
inlineoverridevirtual

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

Implements Signal< SampleType >.

Definition at line 124 of file hart_wavfile.hpp.

◆ represent()

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

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

Implements Signal< SampleType >.

Definition at line 129 of file hart_wavfile.hpp.

◆ HART_SIGNAL_DEFINE_COPY_AND_MOVE()

template<typename SampleType >
HART_SIGNAL_DEFINE_COPY_AND_MOVE ( WavFile< SampleType )

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