Switchboard SDK
Loading...
Searching...
No Matches
switchboard::AudioBuffer< T > Class Template Referencefinal

Provides an abstraction around raw audio buffers stored in memory. More...

#include <AudioBuffer.hpp>

Public Member Functions

WASM AudioBuffer (uint numberOfChannels, uint numberOfFrames, bool isInterleaved, uint sampleRate, T **data)
 Creates an AudioBuffer instance from already allocated memory.
 
 AudioBuffer (uint numberOfChannels, uint numberOfFrames, uint sampleRate, T *data)
 Creates a mono or interleaved AudioBuffer instance from already allocated memory.
 
WASM uint getNumberOfChannels () const
 Returns the number of channels stored in the audio buffer.
 
WASM uint getNumberOfFrames () const
 Returns the number of frames stored in the audio buffer.
 
WASM void setNumberOfFrames (const uint newNumberOfFrames)
 Sets the number of frames in the buffer.
 
WASM bool getIsInterleaved () const
 Returns whether the audio buffer contains interleaved or non-interleaved data. Always false if the audio buffer is mono.
 
WASM uint getSampleRate () const
 Gets the sample rate of the audio buffer.
 
WASM void setSampleRate (const uint newSampleRate)
 Sets the sample rate of the audio buffer.
 
WASM bool isMono () const
 Returns whether the audio buffer is mono.
 
WASM T getSample (uint channel, uint sampleIndex) const
 Returns a sample value from the audio buffer.
 
WASM void setSample (uint channel, uint sampleIndex, T value)
 Sets a sample value in the audio buffer.
 
WASM const T * getReadPointer (uint channel) const
 Returns a read pointer to the data for a channel in the audio buffer.
 
WASM T * getWritePointer (uint channel)
 Returns a write pointer to the data for a channel in the audio buffer.
 
const T ** getReadPointer () const
 Returns a read pointer to the data in the audio buffer.
 
T ** getWritePointer ()
 Returns a write pointer to the data in the audio buffer.
 
void copyFrom (const AudioBuffer< T > &srcBuffer)
 Copies data from another AudioBuffer instance.
 
void clear ()
 Sets all audio sample values to zero.
 

Detailed Description

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

Provides an abstraction around raw audio buffers stored in memory.

AudioBuffer template class.

Can be used with multiple data types such as AudioBuffer<float> or AudioBuffer<int16>.

Constructor & Destructor Documentation

◆ AudioBuffer() [1/2]

template<typename T >
switchboard::AudioBuffer< T >::AudioBuffer ( uint numberOfChannels,
uint numberOfFrames,
bool isInterleaved,
uint sampleRate,
T ** data )

Creates an AudioBuffer instance from already allocated memory.

Parameters
numberOfChannelsThe number of channels.
numberOfFramesThe number of frames.
isInterleavedFlag indicating whether audio data should be interleaved or non-interleaved. Only effective when numberOfChannels > 1.
sampleRateThe sample rate of the audio buffer.
dataPointer to the pre-allocated stacked audio memory location.

◆ AudioBuffer() [2/2]

template<typename T >
switchboard::AudioBuffer< T >::AudioBuffer ( uint numberOfChannels,
uint numberOfFrames,
uint sampleRate,
T * data )

Creates a mono or interleaved AudioBuffer instance from already allocated memory.

Parameters
numberOfChannelsThe number of channels.
numberOfFramesThe number of frames.
sampleRateThe sample rate of the audio buffer.
dataPointer to the pre-allocated mono or interleaved memory location.

Member Function Documentation

◆ copyFrom()

template<typename T >
void switchboard::AudioBuffer< T >::copyFrom ( const AudioBuffer< T > & srcBuffer)

Copies data from another AudioBuffer instance.

Number of channels, number of frames and interleavedness have to be identical in the two audio buffers.

Parameters
srcBufferThe source buffer to copy data from.

◆ getIsInterleaved()

template<typename T >
bool switchboard::AudioBuffer< T >::getIsInterleaved ( ) const

Returns whether the audio buffer contains interleaved or non-interleaved data. Always false if the audio buffer is mono.

Returns
Boolean that is true if the audio data is interleaved, false otherwise or if the audio buffer is mono.

◆ getNumberOfChannels()

template<typename T >
uint switchboard::AudioBuffer< T >::getNumberOfChannels ( ) const

Returns the number of channels stored in the audio buffer.

Returns
The number of channels.

◆ getNumberOfFrames()

template<typename T >
uint switchboard::AudioBuffer< T >::getNumberOfFrames ( ) const

Returns the number of frames stored in the audio buffer.

Returns
The number of frames.

◆ getReadPointer() [1/2]

template<typename T >
const T ** switchboard::AudioBuffer< T >::getReadPointer ( ) const

Returns a read pointer to the data in the audio buffer.

Returns
The read pointer the the audio buffer's data.

◆ getReadPointer() [2/2]

template<typename T >
const T * switchboard::AudioBuffer< T >::getReadPointer ( uint channel) const

Returns a read pointer to the data for a channel in the audio buffer.

Parameters
channelThe index of the channel.
Returns
The read pointer to the channel data.

◆ getSample()

template<typename T >
T switchboard::AudioBuffer< T >::getSample ( uint channel,
uint sampleIndex ) const

Returns a sample value from the audio buffer.

Parameters
channelThe index of the channel.
sampleIndexThe index of the sample.
Returns
The sample value.

◆ getSampleRate()

template<typename T >
uint switchboard::AudioBuffer< T >::getSampleRate ( ) const

Gets the sample rate of the audio buffer.

Returns
The sample rate.

◆ getWritePointer() [1/2]

template<typename T >
T ** switchboard::AudioBuffer< T >::getWritePointer ( )

Returns a write pointer to the data in the audio buffer.

Returns
The write pointer the the audio buffer's data.

◆ getWritePointer() [2/2]

template<typename T >
T * switchboard::AudioBuffer< T >::getWritePointer ( uint channel)

Returns a write pointer to the data for a channel in the audio buffer.

Parameters
channelThe index of the channel.
Returns
The write pointer to the channel data.

◆ isMono()

template<typename T >
bool switchboard::AudioBuffer< T >::isMono ( ) const

Returns whether the audio buffer is mono.

Returns
Boolean that is true if the audio data is single channel, false otherwise.

◆ setNumberOfFrames()

template<typename T >
void switchboard::AudioBuffer< T >::setNumberOfFrames ( const uint newNumberOfFrames)

Sets the number of frames in the buffer.

Parameters
newNumberOfFramesThe new number of frames.

◆ setSample()

template<typename T >
void switchboard::AudioBuffer< T >::setSample ( uint channel,
uint sampleIndex,
T value )

Sets a sample value in the audio buffer.

Parameters
channelThe index of the channel.
sampleIndexThe index of the sample.
valueThe sample value to set.

◆ setSampleRate()

template<typename T >
void switchboard::AudioBuffer< T >::setSampleRate ( const uint newSampleRate)

Sets the sample rate of the audio buffer.

Parameters
newSampleRateThe new sample rate.