RAVENNAKIT
Loading...
Searching...
No Matches
rav::AudioBufferView< T > Class Template Reference

A non-owning view of a non-interleaved audio buffer. More...

#include <audio_buffer_view.hpp>

Inheritance diagram for rav::AudioBufferView< T >:
rav::AudioBuffer< T >

Public Member Functions

 AudioBufferView (T *const *channels, const size_t num_channels, const size_t num_frames)
 Constructs an audio buffer view with the given channels, number of channels, and number of frames.
size_t num_channels () const
size_t num_frames () const
const T * operator[] (size_t channel_index) const
 Accesses the channel at the given index.
T * operator[] (size_t channel_index)
 Accesses the channel at the given index Does not perform bounds checking.
const T *const * data () const
T *const * data ()
void set_sample (size_t channel_index, size_t frame_index, T value)
 Sets the value of an individual sample.
void clear () const
 Clears the buffer by setting all samples to zero.
void clear (T value) const
 Clears the buffer by setting all samples to the given value.
void clear (const size_t channel_index, const size_t start_sample, const size_t num_samples_to_clear)
 Clear a range of samples in a channel, without bounds checking.
void copy_from (const size_t dst_start_frame, const size_t num_frames_to_copy, const T *const *src, const size_t src_num_channels, const size_t src_start_frame=0)
 Copies data from all channels of src into all channels of this buffer.
void copy_from (const size_t dst_channel_index, const size_t dst_start_sample, const size_t num_samples_to_copy, const T *src)
 Copies data from src into this buffer, without bounds checking.
void copy_to (const size_t src_start_frame, const size_t num_frames, T *const *dst, const size_t dst_num_channels, const size_t dst_start_frame=0)
 Copies data from all channels of this buffer into dst.
void copy_to (const size_t src_channel_index, const size_t src_start_sample, const size_t num_samples_to_copy, T *dst)
 Copies data from this buffer into dst.
bool add (const AudioBufferView &other)
 Adds the samples of another audio buffer view to this audio buffer view.
bool is_valid () const
T find_max_abs () const
T find_max_abs (const size_t channel_index) const
 @channel_index The index of the channel to find the maximum value for.
AudioBufferView with_num_channels (const size_t num_channels)
 Returns a copy of this view with given number of channels.
AudioBufferView with_num_frames (const size_t num_frames)
 Returns a copy of this view with given number of frames.
AudioBufferView< std::add_const_t< T > > const_view () const

Protected Member Functions

void update (T *const *channels, const size_t num_channels, const size_t num_frames)
 Updates the channel pointers, number of channels and number of frames.

Friends

bool operator== (const AudioBufferView &lhs, const AudioBufferView &rhs)
 Compares two audio buffers for equality.
bool operator!= (const AudioBufferView &lhs, const AudioBufferView &rhs)
 Compares two audio buffers for inequality.

Detailed Description

template<class T>
class rav::AudioBufferView< T >

A non-owning view of a non-interleaved audio buffer.

Template Parameters
T

Definition at line 35 of file audio_buffer_view.hpp.

Constructor & Destructor Documentation

◆ AudioBufferView()

template<class T>
rav::AudioBufferView< T >::AudioBufferView ( T *const * channels,
const size_t num_channels,
const size_t num_frames )
inline

Constructs an audio buffer view with the given channels, number of channels, and number of frames.

The view does not take ownership or take copies of the data.

Parameters
channelsThe channels.
num_channelsThe number of channels.
num_framesThe number of frames.

Definition at line 44 of file audio_buffer_view.hpp.

Member Function Documentation

◆ add()

template<class T>
bool rav::AudioBufferView< T >::add ( const AudioBufferView< T > & other)
inlinenodiscard

Adds the samples of another audio buffer view to this audio buffer view.

Parameters
otherThe other audio buffer view.
Returns
True if the audio buffer view is valid and the number of channels and frames match, false otherwise.

Definition at line 253 of file audio_buffer_view.hpp.

◆ clear() [1/3]

template<class T>
void rav::AudioBufferView< T >::clear ( ) const
inline

Clears the buffer by setting all samples to zero.

Definition at line 144 of file audio_buffer_view.hpp.

◆ clear() [2/3]

template<class T>
void rav::AudioBufferView< T >::clear ( const size_t channel_index,
const size_t start_sample,
const size_t num_samples_to_clear )
inline

Clear a range of samples in a channel, without bounds checking.

Parameters
channel_indexThe index of the channel.
start_sampleThe index of the first frame to clear.
num_samples_to_clearThe number of samples to clear.

Definition at line 169 of file audio_buffer_view.hpp.

◆ clear() [3/3]

template<class T>
void rav::AudioBufferView< T >::clear ( T value) const
inline

Clears the buffer by setting all samples to the given value.

Parameters
valueThe value to fill the buffer with.

Definition at line 154 of file audio_buffer_view.hpp.

◆ const_view()

template<class T>
AudioBufferView< std::add_const_t< T > > rav::AudioBufferView< T >::const_view ( ) const
inline
Returns
A new AudioBufferView pointing to the same data, but const.

Definition at line 326 of file audio_buffer_view.hpp.

◆ copy_from() [1/2]

template<class T>
void rav::AudioBufferView< T >::copy_from ( const size_t dst_channel_index,
const size_t dst_start_sample,
const size_t num_samples_to_copy,
const T * src )
inline

Copies data from src into this buffer, without bounds checking.

Parameters
dst_channel_indexThe index of the destination channel.
dst_start_sampleThe index of the start frame in the destination channel.
num_samples_to_copyThe number of samples to copy.
srcThe source data to copy from.

Definition at line 201 of file audio_buffer_view.hpp.

◆ copy_from() [2/2]

template<class T>
void rav::AudioBufferView< T >::copy_from ( const size_t dst_start_frame,
const size_t num_frames_to_copy,
const T *const * src,
const size_t src_num_channels,
const size_t src_start_frame = 0 )
inline

Copies data from all channels of src into all channels of this buffer.

Make sure the number of channels and frames match.

Parameters
dst_start_frameThe index of the start frame.
num_frames_to_copyThe number of frames to copy.
srcThe source data to copy from.
src_num_channelsThe number of channels in the source data.
src_start_frameThe index of the start frame in the source data.

Definition at line 184 of file audio_buffer_view.hpp.

◆ copy_to() [1/2]

template<class T>
void rav::AudioBufferView< T >::copy_to ( const size_t src_channel_index,
const size_t src_start_sample,
const size_t num_samples_to_copy,
T * dst )
inline

Copies data from this buffer into dst.

Parameters
src_channel_indexThe index of the source channel.
src_start_sampleThe index of the start frame in the source channel.
num_samples_to_copyThe number of samples to copy.
dstThe destination data to copy to.

Definition at line 237 of file audio_buffer_view.hpp.

◆ copy_to() [2/2]

template<class T>
void rav::AudioBufferView< T >::copy_to ( const size_t src_start_frame,
const size_t num_frames,
T *const * dst,
const size_t dst_num_channels,
const size_t dst_start_frame = 0 )
inline

Copies data from all channels of this buffer into dst.

Parameters
num_framesThe number of frames.
src_start_frameThe index of the start frame in the source data.
dstThe destination data to copy to.
dst_num_channelsThe number of channels.
dst_start_frameThe index of the start frame in the destination data.

Definition at line 220 of file audio_buffer_view.hpp.

◆ data() [1/2]

template<class T>
T *const * rav::AudioBufferView< T >::data ( )
inline
Returns
An array of pointers to the beginning of each channel which can be written to. Might be nullptr if the view is empty.

Definition at line 124 of file audio_buffer_view.hpp.

◆ data() [2/2]

template<class T>
const T *const * rav::AudioBufferView< T >::data ( ) const
inline
Returns
An array of pointers to the beginning of each channel. Might be nullptr if the view is empty.

Definition at line 116 of file audio_buffer_view.hpp.

◆ find_max_abs() [1/2]

template<class T>
T rav::AudioBufferView< T >::find_max_abs ( ) const
inline
Returns
The maximum absolute value of all the samples in the audio buffer.

Definition at line 280 of file audio_buffer_view.hpp.

◆ find_max_abs() [2/2]

template<class T>
T rav::AudioBufferView< T >::find_max_abs ( const size_t channel_index) const
inline

@channel_index The index of the channel to find the maximum value for.

Returns
The maximum absolute value of all the samples in the audio buffer.

Definition at line 294 of file audio_buffer_view.hpp.

◆ is_valid()

template<class T>
bool rav::AudioBufferView< T >::is_valid ( ) const
inlinenodiscard
Returns
True if the audio buffer view is valid, false otherwise. Valid is when the number of channels and frames are greater than zero and the channels are not nullptr.

Definition at line 273 of file audio_buffer_view.hpp.

◆ num_channels()

template<class T>
size_t rav::AudioBufferView< T >::num_channels ( ) const
inlinenodiscard
Returns
The number of channels.

Definition at line 80 of file audio_buffer_view.hpp.

◆ num_frames()

template<class T>
size_t rav::AudioBufferView< T >::num_frames ( ) const
inlinenodiscard
Returns
The number of frames (samples per channel).

Definition at line 87 of file audio_buffer_view.hpp.

◆ operator[]() [1/2]

template<class T>
T * rav::AudioBufferView< T >::operator[] ( size_t channel_index)
inline

Accesses the channel at the given index Does not perform bounds checking.

Parameters
channel_indexThe index of the channel to get.
Returns
A pointer to the beginning of the channel.

Definition at line 108 of file audio_buffer_view.hpp.

◆ operator[]() [2/2]

template<class T>
const T * rav::AudioBufferView< T >::operator[] ( size_t channel_index) const
inline

Accesses the channel at the given index.

Does not perform bounds checking.

Parameters
channel_indexThe index of the channel to get.
Returns
A pointer to the beginning of the channel.

Definition at line 97 of file audio_buffer_view.hpp.

◆ set_sample()

template<class T>
void rav::AudioBufferView< T >::set_sample ( size_t channel_index,
size_t frame_index,
T value )
inline

Sets the value of an individual sample.

This method does no bounds checking.

Parameters
channel_indexThe index of the channel.
frame_indexThe index of the sample.
valueThe value to set.

Definition at line 135 of file audio_buffer_view.hpp.

◆ update()

template<class T>
void rav::AudioBufferView< T >::update ( T *const * channels,
const size_t num_channels,
const size_t num_frames )
inlineprotected

Updates the channel pointers, number of channels and number of frames.

Parameters
channelsThe channels.
num_channelsThe number of channels.
num_framesThe number of frames.

Definition at line 337 of file audio_buffer_view.hpp.

◆ with_num_channels()

template<class T>
AudioBufferView rav::AudioBufferView< T >::with_num_channels ( const size_t num_channels)
inline

Returns a copy of this view with given number of channels.

Parameters
num_channelsThe number of channels. Limited to the current amount of channels.
Returns
A copy of this view with the given number of channels.

Definition at line 310 of file audio_buffer_view.hpp.

◆ with_num_frames()

template<class T>
AudioBufferView rav::AudioBufferView< T >::with_num_frames ( const size_t num_frames)
inline

Returns a copy of this view with given number of frames.

Parameters
num_framesThe number of frames, limited by the current amount of frames.
Returns
A copy of this view with the given number of frames.

Definition at line 319 of file audio_buffer_view.hpp.

◆ operator!=

template<class T>
bool operator!= ( const AudioBufferView< T > & lhs,
const AudioBufferView< T > & rhs )
friend

Compares two audio buffers for inequality.

It does this by comparing the actual contents. If both audio buffers are empty, they are considered equal.

Parameters
lhsLeft hand side audio buffer.
rhsRight hand side audio buffer.
Returns
True if the audio buffers are not equal, false otherwise.

Definition at line 73 of file audio_buffer_view.hpp.

◆ operator==

template<class T>
bool operator== ( const AudioBufferView< T > & lhs,
const AudioBufferView< T > & rhs )
friend

Compares two audio buffers for equality.

It does this by comparing the actual contents. If both audio buffers are empty, they are considered equal.

Parameters
lhsLeft hand side audio buffer.
rhsRight hand side audio buffer.
Returns
True if the audio buffers are equal, false otherwise.

Definition at line 54 of file audio_buffer_view.hpp.


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