Switchboard SDK
Loading...
Searching...
No Matches
switchboard::AudioRingBuffer< T > Class Template Reference

Class providing ring buffer functionality specialized for audio (most importantly multichannel functionality). More...

#include <AudioRingBuffer.hpp>

Public Member Functions

 AudioRingBuffer (const uint numberOfFrames, const uint numberOfChannels, bool isInterleaved)
 Creates an AudioRingBuffer instance. Allocates underlying buffer, constructor not suitable for real-time use.
 
 AudioRingBuffer (const uint numberOfFrames, const uint numberOfChannels, bool isInterleaved, AudioData< T > &buffer)
 Creates an AudioRingBuffer instance. Does not allocate underlying buffer, suitable for real-time use.
 
void clear ()
 Clears all data in the audio ring buffer.
 
const uint getAvailableFramesToProduce () const
 Returns the maximum number of frames that can be added to the audio ring buffer.
 
void produce (const AudioBuffer< T > &sourceBuffer, const uint numberOfFrames)
 Adds frames to the audio ring buffer.
 
const uint getAvailableFramesToConsume () const
 Returns the maximum number of items that can be read from the ring buffer.
 
void consume (AudioBuffer< T > &destinationBuffer, const uint numberOfFrames)
 Reads items from the ring buffer.
 
void read (AudioBuffer< T > &destinationBuffer, uint numberOfItems)
 Reads items from the ring buffer without updating the read pointer.
 
void discard (uint numberOfItems)
 Discards items from the ring buffer. Steps the read pointer without reading the items.
 

Detailed Description

template<typename T>
class switchboard::AudioRingBuffer< T >

Class providing ring buffer functionality specialized for audio (most importantly multichannel functionality).

AudioRingBuffer class.

Constructor & Destructor Documentation

◆ AudioRingBuffer() [1/2]

template<typename T >
switchboard::AudioRingBuffer< T >::AudioRingBuffer ( const uint numberOfFrames,
const uint numberOfChannels,
bool isInterleaved )

Creates an AudioRingBuffer instance. Allocates underlying buffer, constructor not suitable for real-time use.

Parameters
numberOfFramesThe number of frames that the audio ring buffer can hold.
numberOfChannelsThe number of channels that the audio ring buffer can hold.
isInterleavedIndicates whether the audio ring buffer should hold interleaved data.

◆ AudioRingBuffer() [2/2]

template<typename T >
switchboard::AudioRingBuffer< T >::AudioRingBuffer ( const uint numberOfFrames,
const uint numberOfChannels,
bool isInterleaved,
AudioData< T > & buffer )

Creates an AudioRingBuffer instance. Does not allocate underlying buffer, suitable for real-time use.

Does not delete the buffer on destruction. Make sure to handle deletion.

Parameters
numberOfFramesThe number of frames that the audio ring buffer can hold.
numberOfChannelsThe number of channels that the audio ring buffer can hold.
isInterleavedIndicates whether the audio ring buffer should hold interleaved data.
bufferThe underlying buffer(s) the ring buffer is operating on.

Member Function Documentation

◆ consume()

template<typename T >
void switchboard::AudioRingBuffer< T >::consume ( AudioBuffer< T > & destinationBuffer,
const uint numberOfFrames )

Reads items from the ring buffer.

Parameters
destinationBuffer[inout] The buffer where the read frames will be copied to.
numberOfFramesThe number of frames that should be consumed.

◆ discard()

template<typename T >
void switchboard::AudioRingBuffer< T >::discard ( uint numberOfItems)

Discards items from the ring buffer. Steps the read pointer without reading the items.

Parameters
numberOfItemsThe number of items that should be discarded.

◆ getAvailableFramesToConsume()

template<typename T >
const uint switchboard::AudioRingBuffer< T >::getAvailableFramesToConsume ( ) const

Returns the maximum number of items that can be read from the ring buffer.

Returns
The number frames that can be consumed.

◆ getAvailableFramesToProduce()

template<typename T >
const uint switchboard::AudioRingBuffer< T >::getAvailableFramesToProduce ( ) const

Returns the maximum number of frames that can be added to the audio ring buffer.

Returns
The number of frames that can be produced.

◆ produce()

template<typename T >
void switchboard::AudioRingBuffer< T >::produce ( const AudioBuffer< T > & sourceBuffer,
const uint numberOfFrames )

Adds frames to the audio ring buffer.

Parameters
sourceBufferThe buffer where the frames are copied from.
numberOfFramesThe number of frames that should be added to the audio ring buffer.

◆ read()

template<typename T >
void switchboard::AudioRingBuffer< T >::read ( AudioBuffer< T > & destinationBuffer,
uint numberOfItems )

Reads items from the ring buffer without updating the read pointer.

Parameters
destinationBuffer[inout] The buffer where the read frames will be copied to.
numberOfItemsThe number of items that should be consumed.