DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
dspark::AudioBufferView< T, MaxViewChannels > Class Template Reference

Non-owning view over audio channel data. More...

#include <AudioBuffer.h>

Public Member Functions

 AudioBufferView () noexcept=default
 Creates an empty view (0 channels, 0 samples).
 
template<typename U >
 AudioBufferView (U *const *channelPtrs, int numChannels, int numSamples) noexcept
 Constructs a view from an array of channel pointers safely.
 
template<typename U >
 AudioBufferView (const AudioBufferView< U, MaxViewChannels > &other) noexcept
 Converting constructor allowing mutable to const view conversions.
 
T * getChannel (int ch) const noexcept
 Returns a pointer to the sample data for the given channel.
 
int getNumChannels () const noexcept
 Returns the number of channels in this view.
 
int getNumSamples () const noexcept
 Returns the number of samples per channel.
 
AudioBufferView getSubView (int startSample, int length) const noexcept
 Returns a zero-copy sub-view starting at an offset.
 
void clear () const noexcept
 Fills the valid sample range of all channels with zeros.
 
template<typename U , int M>
void copyFrom (const AudioBufferView< U, M > &src) const noexcept
 Safely copies samples from a source view into this view.
 
template<typename U , int M>
void addFrom (const AudioBufferView< U, M > &src, T gain=T(1)) const noexcept
 Adds samples from a source view into this view with optional gain.
 
void applyGain (T gain) const noexcept
 Multiplies all samples in all valid channels by a gain factor.
 
std::remove_const_t< T > getPeakLevel () const noexcept
 Returns the peak absolute sample value across all channels.
 

Detailed Description

template<typename T, int MaxViewChannels = 16>
class dspark::AudioBufferView< T, MaxViewChannels >

Non-owning view over audio channel data.

Template Parameters
TSample type (typically float, double, const float, or const double).
MaxViewChannelsCompile-time limit for the internal pointer array.

Definition at line 49 of file AudioBuffer.h.

Constructor & Destructor Documentation

◆ AudioBufferView() [1/3]

template<typename T , int MaxViewChannels = 16>
dspark::AudioBufferView< T, MaxViewChannels >::AudioBufferView ( )
defaultnoexcept

Creates an empty view (0 channels, 0 samples).

◆ AudioBufferView() [2/3]

template<typename T , int MaxViewChannels = 16>
template<typename U >
dspark::AudioBufferView< T, MaxViewChannels >::AudioBufferView ( U *const *  channelPtrs,
int  numChannels,
int  numSamples 
)
inlinenoexcept

Constructs a view from an array of channel pointers safely.

Template Parameters
UType of the source pointers (must be convertible to T*).
Parameters
channelPtrsArray of pointers, one per channel.
numChannelsNumber of active channels.
numSamplesNumber of samples per channel.

Definition at line 63 of file AudioBuffer.h.

◆ AudioBufferView() [3/3]

template<typename T , int MaxViewChannels = 16>
template<typename U >
dspark::AudioBufferView< T, MaxViewChannels >::AudioBufferView ( const AudioBufferView< U, MaxViewChannels > &  other)
inlinenoexcept

Converting constructor allowing mutable to const view conversions.

Enables passing AudioBufferView<float> to functions expecting AudioBufferView<const float>.

Template Parameters
USource sample type.
Parameters
otherThe view to convert from.

Definition at line 88 of file AudioBuffer.h.

Member Function Documentation

◆ addFrom()

template<typename T , int MaxViewChannels = 16>
template<typename U , int M>
void dspark::AudioBufferView< T, MaxViewChannels >::addFrom ( const AudioBufferView< U, M > &  src,
gain = T(1) 
) const
inlinenoexcept

Adds samples from a source view into this view with optional gain.

Channel count and length are trimmed to the smaller of the two views. Unlike copyFrom(), the source must NOT overlap this view: the mix goes through restrict-qualified SIMD kernels (see SimdOps.h).

Template Parameters
USource sample type.
MSource view channel capacity (any capacity is accepted).
Parameters
srcSource view.
gainScaling factor.

Definition at line 197 of file AudioBuffer.h.

◆ applyGain()

template<typename T , int MaxViewChannels = 16>
void dspark::AudioBufferView< T, MaxViewChannels >::applyGain ( gain) const
inlinenoexcept

Multiplies all samples in all valid channels by a gain factor.

Parameters
gainScaling factor.

Definition at line 225 of file AudioBuffer.h.

◆ clear()

template<typename T , int MaxViewChannels = 16>
void dspark::AudioBufferView< T, MaxViewChannels >::clear ( ) const
inlinenoexcept

Fills the valid sample range of all channels with zeros.

Definition at line 138 of file AudioBuffer.h.

◆ copyFrom()

template<typename T , int MaxViewChannels = 16>
template<typename U , int M>
void dspark::AudioBufferView< T, MaxViewChannels >::copyFrom ( const AudioBufferView< U, M > &  src) const
inlinenoexcept

Safely copies samples from a source view into this view.

For same-type trivially-copyable samples the copy goes through std::memmove, which is guaranteed safe even when the ranges overlap. Channel count and length are trimmed to the smaller of the two views.

Template Parameters
USource sample type.
MSource view channel capacity (any capacity is accepted).
Parameters
srcSource view to copy from.

Definition at line 160 of file AudioBuffer.h.

◆ getChannel()

template<typename T , int MaxViewChannels = 16>
T * dspark::AudioBufferView< T, MaxViewChannels >::getChannel ( int  ch) const
inlinenoexcept

Returns a pointer to the sample data for the given channel.

Definition at line 100 of file AudioBuffer.h.

◆ getNumChannels()

template<typename T , int MaxViewChannels = 16>
int dspark::AudioBufferView< T, MaxViewChannels >::getNumChannels ( ) const
inlinenoexcept

Returns the number of channels in this view.

Definition at line 107 of file AudioBuffer.h.

◆ getNumSamples()

template<typename T , int MaxViewChannels = 16>
int dspark::AudioBufferView< T, MaxViewChannels >::getNumSamples ( ) const
inlinenoexcept

Returns the number of samples per channel.

Definition at line 110 of file AudioBuffer.h.

◆ getPeakLevel()

template<typename T , int MaxViewChannels = 16>
std::remove_const_t< T > dspark::AudioBufferView< T, MaxViewChannels >::getPeakLevel ( ) const
inlinenoexcept

Returns the peak absolute sample value across all channels.

Returns
Peak magnitude (>= 0).

Definition at line 236 of file AudioBuffer.h.

◆ getSubView()

template<typename T , int MaxViewChannels = 16>
AudioBufferView dspark::AudioBufferView< T, MaxViewChannels >::getSubView ( int  startSample,
int  length 
) const
inlinenoexcept

Returns a zero-copy sub-view starting at an offset.

Parameters
startSampleOffset from the beginning of each channel.
lengthNumber of samples in the sub-view.
Returns
A new AudioBufferView referencing the sub-range.

Definition at line 120 of file AudioBuffer.h.


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