AME
All Classes Files Functions Variables Enumerations Enumerator
ame::AudioBlockView< ElementType, Extent > Class Template Reference

A lightweight data structure that stores a pointer to an audio buffer. More...

#include <ame_AudioBuffer.hpp>

Public Member Functions

 AudioBlockView (std::span< ElementType, Extent > view, const uint_fast32_t numChannels) noexcept
 Constructor. More...
 
uint_fast32_t getNumChannels () const noexcept
 Returns the number of channels.
 
uint_fast32_t getNumSamplesPerChannel () const noexcept
 Returns the number of samples per channel.
 
void setSample (const uint_fast32_t destChannel, const uint_fast32_t destSample, const ElementType newValue)
 Set a sample in the buffer. More...
 
void addSample (const uint_fast32_t destChannel, const uint_fast32_t destSample, const ElementType valueToAdd)
 Add a value to a sample in the buffer. More...
 
void clear ()
 Set all samples to 0.
 
void applyGain (const float gain)
 Applies a gain multiple to all the audio data.
 
float getPeak (const uint_fast32_t channel) const
 Finds the highest absolute sample value within a region of a channel. More...
 
float getRMSLevel (const uint_fast32_t channel) const
 Returns the root mean squared level for a region of a channel. More...
 
auto subView (uint_fast32_t offset, uint_fast32_t size)
 Returns an AudioBlockView that references N elements from an arbitrary position. More...
 

Public Attributes

std::span< ElementType, Extent > view
 

Detailed Description

template<class ElementType, size_t Extent>
class ame::AudioBlockView< ElementType, Extent >

A lightweight data structure that stores a pointer to an audio buffer.

This class doesn't own any of the data which it points to, it's simply a view into data that is owned elsewhere. You can construct one from some raw data that you've allocated yourself, or give it an AudioBuffer which it can refer to, but in all cases the user is responsible for making sure that the data doesn't get deleted while there's still an AudioBlock using it.

Attention
Channel order is interleaved.
See also
AudioBuffer

Constructor & Destructor Documentation

◆ AudioBlockView()

template<class ElementType , size_t Extent>
ame::AudioBlockView< ElementType, Extent >::AudioBlockView ( std::span< ElementType, Extent >  view,
const uint_fast32_t  numChannels 
)
inlinenoexcept

Constructor.

Parameters
bufferInterleaved audio buffer view.
numChannelsthe number of channels.
numSamplesthe number of samples in each of the buffer's channels.
Attention
The order of ame's audio buffers is interleaved. Note that it is NOT channel-splitting.

Member Function Documentation

◆ addSample()

template<class ElementType , size_t Extent>
void ame::AudioBlockView< ElementType, Extent >::addSample ( const uint_fast32_t  destChannel,
const uint_fast32_t  destSample,
const ElementType  valueToAdd 
)
inline

Add a value to a sample in the buffer.

Parameters
destChannel
destSample
valueToAdd

◆ getPeak()

template<class ElementType , size_t Extent>
float ame::AudioBlockView< ElementType, Extent >::getPeak ( const uint_fast32_t  channel) const
inline

Finds the highest absolute sample value within a region of a channel.


Parameters
channel
Returns
FloatType [0.0, FloatTypeMax]

◆ getRMSLevel()

template<class ElementType , size_t Extent>
float ame::AudioBlockView< ElementType, Extent >::getRMSLevel ( const uint_fast32_t  channel) const
inline

Returns the root mean squared level for a region of a channel.

Parameters
channel
Returns
FloatType RMS level [0.0, SampleTypeMax]

◆ setSample()

template<class ElementType , size_t Extent>
void ame::AudioBlockView< ElementType, Extent >::setSample ( const uint_fast32_t  destChannel,
const uint_fast32_t  destSample,
const ElementType  newValue 
)
inline

Set a sample in the buffer.


Parameters
destChannel
destSample
value

◆ subView()

template<class ElementType , size_t Extent>
auto ame::AudioBlockView< ElementType, Extent >::subView ( uint_fast32_t  offset,
uint_fast32_t  size 
)
inline

Returns an AudioBlockView that references N elements from an arbitrary position.

Parameters
offsetStart location
sizeNumber of elements
Returns
ame::AudioBlockView
See also
std::span::subspan()
ame::AudioBuffer::makeAudioBlockView()
Attention
Be careful that size is NOT the number of samples per channel, but the size of std::span.

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