|
HART
0.2.0
High level Audio Regression and Testing
|
Container for audio data. More...
#include <hart_audio_buffer.hpp>
Public Member Functions | |
| AudioBuffer (size_t numChannels=0, size_t numFrames=0, double sampleRateHz=nan< double >()) | |
| Creates an audio buffer. | |
| AudioBuffer (const AudioBuffer &other) | |
| Creates an audio buffer by copying. | |
| AudioBuffer (AudioBuffer &&other) noexcept | |
| Creates an audio buffer by moving. | |
| ~AudioBuffer ()=default | |
| The destructor. | |
| AudioBuffer & | operator= (const AudioBuffer &other) |
| Creates an audio buffer by copy-assigning. | |
| AudioBuffer & | operator= (AudioBuffer &&other) noexcept |
| Creates an audio buffer by move-assigning. | |
| const SampleType *const * | getArrayOfReadPointers () const |
| Gets a raw pointer to the read-only audio data. | |
| SampleType *const * | getArrayOfWritePointers () |
| Gets a raw pointer to the mutable audio data. | |
| size_t | getNumChannels () const |
| Get number of channels. | |
| size_t | getNumFrames () const |
| Get number of frames (samples) | |
| void | setNumFrames (size_t newNumFrames) |
| Resizes the buffer to hold a new number of frames per channel. | |
| bool | hasSampleRate () const |
| Check if a specific sample rate was assigned to the audio buffer. | |
| double | getSampleRateHz () const |
| Get a sample rate metadata. | |
| double | getLengthSeconds () const |
| Get a duration of the audio buffer. | |
| SampleType * | operator[] (size_t channel) |
| Get a raw pointer to a specific channel's mutable audio data. | |
| const SampleType * | operator[] (size_t channel) const |
| Get a raw pointer to a specific channel's read-only audio data. | |
| bool | equalsTo (const AudioBuffer &other, SampleType toleranceLinear=(SampleType) 1e-6) const |
| Checks whether this buffer contains approximately the same audio as another buffer. | |
| bool | operator== (const AudioBuffer &other) const |
| Checks whether two buffers contain approximately the same audio. | |
| bool | operator!= (const AudioBuffer &other) const |
| Checks whether two buffers differ beyond the default comparison tolerance. | |
| void | appendFrom (const AudioBuffer< SampleType > &otherBuffer) |
| Appends data from another buffer. | |
| void | erase () |
| Clears the buffer. | |
| SampleType | getMagnitude (size_t channel, size_t startFrame, size_t numFrames) const |
| Get the maximum absolute value in the buffer in a specific channel. | |
| SampleType | getMagnitude (size_t startFrame, size_t numFrames) const |
| Get the maximum absolute value in the buffer across all channels. | |
| void | copyFrom (size_t destChannel, size_t destStartFrame, const AudioBuffer &source, size_t sourceChannel, size_t sourceStartFrame, size_t numFrames) |
| Copies audio from another buffer. | |
| void | copyFrom (size_t destChannel, size_t destStartFrame, const SampleType *source, size_t numFrames) |
| Copies audio from another generic audio buffer. | |
| void | clear () |
| Clears the entire buffer. | |
| void | clear (size_t channel, size_t startFrame, size_t numFrames) |
| Clears a specific section of a given channel. | |
| void | represent (std::ostream &stream) const |
| Prints readable representation of the audio buffer. | |
| AudioBuffer< SampleType > & | fillWith (SignalBase< SampleType > &signal, size_t blockSizeFrames=0, Preparation signalPreparation=Preparation::resetAndPrepare) & |
| Fills this AudioBuffer by rendering audio from a Signal. | |
| AudioBuffer< SampleType > & | fillWith (SignalBase< SampleType > &&signal, size_t blockSizeFrames=0, Preparation signalPreparation=Preparation::resetAndPrepare) & |
| Fills this AudioBuffer by rendering audio from a Signal. | |
| AudioBuffer< SampleType > && | fillWith (SignalBase< SampleType > &signal, size_t blockSizeFrames=0, Preparation signalPreparation=Preparation::resetAndPrepare) && |
| Fills this AudioBuffer by rendering audio from a Signal. | |
| AudioBuffer< SampleType > && | fillWith (SignalBase< SampleType > &&signal, size_t blockSizeFrames=0, Preparation signalPreparation=Preparation::resetAndPrepare) && |
| Fills this AudioBuffer by rendering audio from a Signal. | |
| AudioBuffer< SampleType > & | processWith (DSPBase< SampleType > &dsp, size_t blockSizeFrames=0, Preparation dspPreparation=Preparation::resetAndPrepare) & |
| Processes this AudioBuffer by rendering its audio through a provided DSP. | |
| AudioBuffer< SampleType > & | processWith (DSPBase< SampleType > &&dsp, size_t blockSizeFrames=0, Preparation dspPreparation=Preparation::resetAndPrepare) & |
| Processes this AudioBuffer by rendering its audio through a provided DSP. | |
| AudioBuffer< SampleType > && | processWith (DSPBase< SampleType > &dsp, size_t blockSizeFrames=0, Preparation dspPreparation=Preparation::resetAndPrepare) && |
| Processes this AudioBuffer by rendering its audio through a provided DSP. | |
| AudioBuffer< SampleType > && | processWith (DSPBase< SampleType > &&dsp, size_t blockSizeFrames=0, Preparation dspPreparation=Preparation::resetAndPrepare) && |
| Processes this AudioBuffer by rendering its audio through a provided DSP. | |
| std::pair< size_t, size_t > | getFrameIndices (const Slice &slice) const |
| Returns a pair of indices representing a provided slice. | |
Static Public Member Functions | |
| static AudioBuffer | emptyLike (const AudioBuffer &other) |
Creates an empty audio buffer with the same number of channels, frames and sample rate as the other buffer. | |
Friends | |
| std::ostream & | operator<< (std::ostream &stream, const AudioBuffer &audioBuffer) |
| Prints readable text representation of the AudioBuffer object into the I/O stream. | |
Container for audio data.
Definition at line 26 of file hart_audio_buffer.hpp.
|
inline |
Creates an audio buffer.
| numChannels | Initial number of channels |
| numFrames | Numbers of frames (samples) to be allocated in each channel |
| sampleRateHz | Metadata for sample rate (in Hz) in which the data whould be interpreted, whenever applicable |
Definition at line 33 of file hart_audio_buffer.hpp.
|
inline |
Creates an audio buffer by copying.
Definition at line 44 of file hart_audio_buffer.hpp.
|
inlinenoexcept |
Creates an audio buffer by moving.
Definition at line 55 of file hart_audio_buffer.hpp.
|
default |
The destructor.
|
inline |
Creates an audio buffer by copy-assigning.
Definition at line 69 of file hart_audio_buffer.hpp.
|
inlinenoexcept |
Creates an audio buffer by move-assigning.
Definition at line 87 of file hart_audio_buffer.hpp.
|
inline |
Gets a raw pointer to the read-only audio data.
Definition at line 105 of file hart_audio_buffer.hpp.
|
inline |
Gets a raw pointer to the mutable audio data.
Definition at line 113 of file hart_audio_buffer.hpp.
|
inlinestatic |
Creates an empty audio buffer with the same number of channels, frames and sample rate as the other buffer.
| other | Reference buffer |
Definition at line 121 of file hart_audio_buffer.hpp.
|
inline |
Get number of channels.
Definition at line 130 of file hart_audio_buffer.hpp.
|
inline |
Get number of frames (samples)
Definition at line 134 of file hart_audio_buffer.hpp.
|
inline |
Resizes the buffer to hold a new number of frames per channel.
Resizing behaviour:
| newNumFrames | New number of frames per channel |
Definition at line 144 of file hart_audio_buffer.hpp.
|
inline |
Check if a specific sample rate was assigned to the audio buffer.
true if there is a specific sample rate value, false otherwise Definition at line 177 of file hart_audio_buffer.hpp.
|
inline |
Get a sample rate metadata.
hasSampleRate() if you're not sure if the buffer has a specific sample rate Definition at line 185 of file hart_audio_buffer.hpp.
|
inline |
Get a duration of the audio buffer.
hasSampleRate() to check if the buffer has a specific sample rate, otherwise the duration is unknown. Definition at line 194 of file hart_audio_buffer.hpp.
|
inline |
Get a raw pointer to a specific channel's mutable audio data.
getNumFrames() items and to be a contiguous non-interleaved block of memory. Definition at line 207 of file hart_audio_buffer.hpp.
|
inline |
Get a raw pointer to a specific channel's read-only audio data.
getNumFrames() items and to be a contiguous non-interleaved block of memory. Definition at line 215 of file hart_audio_buffer.hpp.
|
inline |
Checks whether this buffer contains approximately the same audio as another buffer.
The comparison is relaxed - each pair of corresponding samples must differ by no more than toleranceLinear, but not bit-exact. Both buffers must have the same number of channels and frames. Also, if both buffers have sample-rate metadata, the sample rates must match. If both buffers have no sample-rate metadata assigned, they will still be considered equal as long as their dimensions match, and sample values match within tolerance.
| other | Buffer to compare against |
| toleranceLinear | Absolute sample tolerance in linear domain (not decibels) |
true if the buffers are equal within the specified tolerance, false otherwise Definition at line 229 of file hart_audio_buffer.hpp.
|
inline |
Checks whether two buffers contain approximately the same audio.
Equivalent to calling AudioBuffer::equalsTo (other) with the default tolerance
| other | Buffer to compare against |
true if the buffers are equal within the default tolerance, false otherwise Definition at line 252 of file hart_audio_buffer.hpp.
|
inline |
Checks whether two buffers differ beyond the default comparison tolerance.
Equivalent to ! AudioBuffer::equalsTo (other)
| other | Buffer to compare against |
true if the buffers are not equal within the default tolerance, false otherwise Definition at line 261 of file hart_audio_buffer.hpp.
|
inline |
Appends data from another buffer.
getArrayOfReadPointers(), getArrayOfWritePointers() and the "`[]`" operator, so make sure to keep those external pointers up to date. | otherBuffer | A buffer to append from |
Definition at line 270 of file hart_audio_buffer.hpp.
|
inline |
Clears the buffer.
The number of frames after this operation will be zero, but channel number will persist.
Definition at line 298 of file hart_audio_buffer.hpp.
|
inline |
Get the maximum absolute value in the buffer in a specific channel.
| channel | Channel of which the magnitude should be measured |
| startFrame | The beginning of the range of the frames to look for magnitude |
| numFrames | Number of frames, beginning with startFrame, to look for the magnitude |
Definition at line 317 of file hart_audio_buffer.hpp.
|
inline |
Get the maximum absolute value in the buffer across all channels.
| startFrame | The beginning of the range of the frames to look for magnitude |
| numFrames | Number of frames, beginning with startFrame, to look for the magnitude |
Definition at line 339 of file hart_audio_buffer.hpp.
|
inline |
Copies audio from another buffer.
| destChannel | Channel within this buffer to copy the frames to |
| destStartFrame | Start frame within this buffer's channel |
| source | Source buffer to read from |
| sourceChannel | Channel within the source buffer to read from |
| sourceStartFrame | Offset within the source buffer's channel to start reading frames from |
| numFrames | Number of frames to copy |
Definition at line 367 of file hart_audio_buffer.hpp.
|
inline |
Copies audio from another generic audio buffer.
| destChannel | Channel within this buffer to copy the frames to |
| destStartFrame | Start frame within this buffer's channel |
| source | Pointer to the source sample data, must contain at least numFrames samples |
| numFrames | Number of frames to copy |
Definition at line 390 of file hart_audio_buffer.hpp.
|
inline |
Clears the entire buffer.
Sets all frames in all channels to zeros, keeping the sample rate value intact
Definition at line 403 of file hart_audio_buffer.hpp.
|
inline |
Clears a specific section of a given channel.
Overwrites a selected section of the channel with zeros
| channel | Channel in which to clear a frame range |
| startFrame | Start of the frame range to clear (inclusive) |
| numFrames | Amount of frames to clear |
Definition at line 413 of file hart_audio_buffer.hpp.
|
inline |
Prints readable representation of the audio buffer.
| stream | String stream to append the representation to |
Definition at line 426 of file hart_audio_buffer.hpp.
|
inline |
Fills this AudioBuffer by rendering audio from a Signal.
This method uses the supplied Signal and renders audio into this buffer, replacing all existing samples. The Signal is not consumed and can be re-used after rendering completes.
The buffer's sample rate and channel layout are used as the hosting configuration. If the Signal does not support the current channel count or sample rate, an exception is raised.
Rendering is performed block-by-block when blockSizeFrames is smaller than the buffer length. The final block may be shorter than the requested block size.
| signal | A reusable Signal object to render from. |
| blockSizeFrames | Number of frames to render per block. Pass 0 to render the whole buffer in one go. |
| signalPreparation | Controls whether the Signal should be reset and/or prepared before rendering. |
| hart::SampleRateError | if Sample rate of this buffer is undefined, or unsupported by the Signal. |
| hart::ChannelLayoutError | if this buffer has no channels allocated, or number of channels is unsupported by the Signal |
| hart::SizeError | is this buffer has no frames allocated |
Definition at line 454 of file hart_audio_buffer.hpp.
|
inline |
Fills this AudioBuffer by rendering audio from a Signal.
This method uses the supplied Signal and renders audio into this buffer, replacing all existing samples.
The buffer's sample rate and channel layout are used as the hosting configuration. If the Signal does not support the current channel count or sample rate, an exception is raised.
Rendering is performed block-by-block when blockSizeFrames is smaller than the buffer length. The final block may be shorter than the requested block size.
| signal | A temporary Signal instance to render from. |
| blockSizeFrames | Number of frames to render per block. Pass 0 to render the whole buffer in one go. |
| signalPreparation | Controls whether the Signal should be reset and/or prepared before rendering. |
| hart::SampleRateError | if Sample rate of this buffer is undefined, or unsupported by the Signal. |
| hart::ChannelLayoutError | if this buffer has no channels allocated, or number of channels is unsupported by the Signal |
| hart::SizeError | is this buffer has no frames allocated |
Definition at line 477 of file hart_audio_buffer.hpp.
|
inline |
Fills this AudioBuffer by rendering audio from a Signal.
This method uses the supplied Signal and renders audio into this buffer, replacing all existing samples. The Signal is not consumed and can be re-used after rendering completes.
The buffer's sample rate and channel layout are used as the hosting configuration. If the Signal does not support the current channel count or sample rate, an exception is raised.
Rendering is performed block-by-block when blockSizeFrames is smaller than the buffer length. The final block may be shorter than the requested block size.
| signal | A reusable Signal object to render from. |
| blockSizeFrames | Number of frames to render per block. Pass 0 to render the whole buffer in one go. |
| signalPreparation | Controls whether the Signal should be reset and/or prepared before rendering. |
| hart::SampleRateError | if Sample rate of this buffer is undefined, or unsupported by the Signal. |
| hart::ChannelLayoutError | if this buffer has no channels allocated, or number of channels is unsupported by the Signal |
| hart::SizeError | is this buffer has no frames allocated |
Definition at line 501 of file hart_audio_buffer.hpp.
|
inline |
Fills this AudioBuffer by rendering audio from a Signal.
This method uses the supplied Signal and renders audio into this buffer, replacing all existing samples.
The buffer's sample rate and channel layout are used as the hosting configuration. If the Signal does not support the current channel count or sample rate, an exception is raised.
Rendering is performed block-by-block when blockSizeFrames is smaller than the buffer length. The final block may be shorter than the requested block size.
| signal | A temporary Signal instance to render from. |
| blockSizeFrames | Number of frames to render per block. Pass 0 to render the whole buffer in one go. |
| signalPreparation | Controls whether the Signal should be reset and/or prepared before rendering. |
| hart::SampleRateError | if Sample rate of this buffer is undefined, or unsupported by the Signal. |
| hart::ChannelLayoutError | if this buffer has no channels allocated, or number of channels is unsupported by the Signal |
| hart::SizeError | is this buffer has no frames allocated |
Definition at line 524 of file hart_audio_buffer.hpp.
|
inline |
Processes this AudioBuffer by rendering its audio through a provided DSP.
This method uses the supplied DSP and renders audio from this buffer, replacing all existing samples. The DSP is not consumed and can be re-used after rendering completes.
The buffer's sample rate and channel layout are used as the hosting configuration. If the DSP does not support the current channel count or sample rate, an exception is raised.
Rendering is performed block-by-block when blockSizeFrames is smaller than the buffer length. The final block may be shorter than the requested block size.
| signal | A reusable hart::DSP object to render from |
| blockSizeFrames | Number of frames to render per block. Pass 0 to render the whole buffer in one go |
| signalPreparation | Controls whether the DSP object should be reset and/or prepared before rendering |
| hart::SampleRateError | if Sample rate of this buffer is undefined, or unsupported by the DSP object |
| hart::ChannelLayoutError | if this buffer has no channels allocated, or number of channels is unsupported by the DSP object |
| hart::SizeError | is this buffer has no frames allocated |
Definition at line 548 of file hart_audio_buffer.hpp.
|
inline |
Processes this AudioBuffer by rendering its audio through a provided DSP.
This method uses the supplied DSP and renders audio from this buffer, replacing all existing samples
The buffer's sample rate and channel layout are used as the hosting configuration. If the DSP does not support the current channel count or sample rate, an exception is raised.
Rendering is performed block-by-block when blockSizeFrames is smaller than the buffer length The final block may be shorter than the requested block size
| signal | A temporary hart::DSP object to process AudioBuffer's contents with |
| blockSizeFrames | Number of frames to render per block. Pass 0 to render the whole buffer in one go. |
| signalPreparation | Controls whether the DSP object should be reset and/or prepared before rendering |
| hart::SampleRateError | if Sample rate of this buffer is undefined, or unsupported by the DSP object |
| hart::ChannelLayoutError | if this buffer has no channels allocated, or number of channels is unsupported by the DSP object |
| hart::SizeError | is this buffer has no frames allocated |
Definition at line 571 of file hart_audio_buffer.hpp.
|
inline |
Processes this AudioBuffer by rendering its audio through a provided DSP.
This method uses the supplied DSP and renders audio from this buffer, replacing all existing samples. The DSP is not consumed and can be re-used after rendering completes.
The buffer's sample rate and channel layout are used as the hosting configuration. If the DSP does not support the current channel count or sample rate, an exception is raised.
Rendering is performed block-by-block when blockSizeFrames is smaller than the buffer length. The final block may be shorter than the requested block size.
| signal | A reusable hart::DSP object to render from |
| blockSizeFrames | Number of frames to render per block. Pass 0 to render the whole buffer in one go. |
| signalPreparation | Controls whether the DSP object should be reset and/or prepared before rendering. |
| hart::SampleRateError | if Sample rate of this buffer is undefined, or unsupported by the DSP object |
| hart::ChannelLayoutError | if this buffer has no channels allocated, or number of channels is unsupported by the DSP object |
| hart::SizeError | is this buffer has no frames allocated |
Definition at line 595 of file hart_audio_buffer.hpp.
|
inline |
Processes this AudioBuffer by rendering its audio through a provided DSP.
This method uses the supplied DSP and renders audio from this buffer, replacing all existing samples.
The buffer's sample rate and channel layout are used as the hosting configuration. If the DSP does not support the current channel count or sample rate, an exception is raised.
Rendering is performed block-by-block when blockSizeFrames is smaller than the buffer length. The final block may be shorter than the requested block size.
| signal | A temporary hart::DSP object to process AudioBuffer's contents with |
| blockSizeFrames | Number of frames to render per block. Pass 0 to render the whole buffer in one go. |
| signalPreparation | Controls whether the DSP object should be reset and/or prepared before rendering |
| hart::SampleRateError | if Sample rate of this buffer is undefined, or unsupported by the DSP object |
| hart::ChannelLayoutError | if this buffer has no channels allocated, or number of channels is unsupported by the DSP object |
| hart::SizeError | is this buffer has no frames allocated |
Definition at line 618 of file hart_audio_buffer.hpp.
|
inline |
Returns a pair of indices representing a provided slice.
| slice | A Slice instance. Valid slice types are Slice::Type::whole Slice::Type::frames and Slice::Type::time |
| first | Index representing the beginning of the range, inclusive |
| second | Index representing the end of the range, non-inclusive |
Definition at line 629 of file hart_audio_buffer.hpp.
|
friend |
Prints readable text representation of the AudioBuffer object into the I/O stream.
Definition at line 685 of file hart_audio_buffer.hpp.