SynthLab SDK
SynthLab::AudioBuffer Class Reference

Encapsulates the audio buffering requirements of any module that uses audio samples for input and/or output. More...

#include <synthbase.h>

Inheritance diagram for SynthLab::AudioBuffer:
SynthLab::SynthProcessInfo

Public Member Functions

 AudioBuffer (uint32_t _numInputChannels, uint32_t _numOutputChannels, uint32_t _blockSize)
 Specialized constructor that initializes the buffers during construction. More...
 
 ~AudioBuffer ()
 As one of the few objects that uses naked pointers (for maximum compatibility between plugin frameworks and/or plugin APIs and the easiest of use) this deletes the audio buffer arrays.
 
void init (uint32_t _numInputChannels, uint32_t _numOutputChannels, uint32_t _blockSize)
 Main initializer that creates the new arrays and sets up the object. More...
 
void flushBuffers ()
 clear out the audio; used often More...
 
float * getInputBuffer (uint32_t channel)
 Get a naked pointer to an audio INPUT buffer by channel. More...
 
float * getOutputBuffer (uint32_t channel)
 Get a naked pointer to an audio OUTPUT buffer by channel. More...
 
float ** getInputBuffers ()
 
float ** getOutputBuffers ()
 
uint32_t getInputChannelCount ()
 
uint32_t getOutputChannelCount ()
 
uint32_t getBlockSize ()
 
uint32_t getSamplesInBlock ()
 
void setSamplesInBlock (uint32_t _samplesInBlock)
 Set the number of samples in a block for processing. More...
 

Protected Member Functions

void destroyInputBuffers ()
 Destroy dynamically allocated input buffer; done at destruct time, or if client want to re-size buffers.
 
void destroyOutputBuffers ()
 Destroy dynamically allocated output buffer; done at destruct time, or if client want to re-size buffers.
 

Protected Attributes

float ** inputBuffer = nullptr
 array of input buffer pointers
 
float ** outputBuffer = nullptr
 array of output buffer pointers
 
uint32_t numInputChannels = 1
 
uint32_t numOutputChannels = 1
 
uint32_t blockSize = 64
 the maximum block size
 
uint32_t samplesInBlock = 64
 the number of samples to process in the block (in case of partial blocks)
 

Detailed Description

Encapsulates the audio buffering requirements of any module that uses audio samples for input and/or output.

  • includes sepearate audio input and output buffers (arrays)
  • audio buffers are channel-independent so there are separate Left and Right channel buffers for each direction
  • automatically supports multi-channel operation beyond stereo
  • follows identical design pattern as that used in all plugin APIs and DAWs
  • uses float buffers for maximum compatibility across target APIs and DAWs
  • audio buffers are used to move frequency modulation values (FM) or phase modualtion values (PM) in addition to the normal input/output
  • FM and PM buffers are also categorized as INPUT or OUTPU depending on origin and destination
Author
Will Pirkle http://www.willpirkle.com
Remarks
This object is included and described in further detail in Designing Software Synthesizer Plugins in C++ 2nd Ed. by Will Pirkle
Version
Revision : 1.0
Date
Date : 2021 / 04 / 26

Constructor & Destructor Documentation

◆ AudioBuffer()

SynthLab::AudioBuffer::AudioBuffer ( uint32_t  _numInputChannels,
uint32_t  _numOutputChannels,
uint32_t  _blockSize 
)

Specialized constructor that initializes the buffers during construction.

Parameters
_numInputChannelsinput channel count (1 = mono, 2 = stereo, may be greater than 2 if needed)
_numOutputChannelsinput channel count (1 = mono, 2 = stereo, may be greater than 2 if needed)
_blockSizethe MAXIMUM block size that sets the buffer sizes; this can never be exceeded

Member Function Documentation

◆ flushBuffers()

void SynthLab::AudioBuffer::flushBuffers ( )

clear out the audio; used often

Fast clearing of audio buffer data; this is important because buffers are re-used all the time.

◆ getBlockSize()

uint32_t SynthLab::AudioBuffer::getBlockSize ( )
inline

current block size in frames - one sample per channel

◆ getInputBuffer()

float * SynthLab::AudioBuffer::getInputBuffer ( uint32_t  channel)

Get a naked pointer to an audio INPUT buffer by channel.

get a pointer to an input or output buffer for a certain channel

  • for mono/stereo operation: channel 0 = mono or left, channel 1 = right
  • may also be used with > 2 channel operation
Parameters
channelindex of channel to get input buffer

◆ getInputBuffers()

float** SynthLab::AudioBuffer::getInputBuffers ( )
inline

arrays of pointers to ALL input and output buffers

◆ getInputChannelCount()

uint32_t SynthLab::AudioBuffer::getInputChannelCount ( )
inline

get number of input or output channels; these valued do not change once initialized

◆ getOutputBuffer()

float * SynthLab::AudioBuffer::getOutputBuffer ( uint32_t  channel)

Get a naked pointer to an audio OUTPUT buffer by channel.

  • for mono/stereo operation: channel 0 = mono or left, channel 1 = right
  • may also be used with > 2 channel operation
Parameters
channelindex of channel to get input buffer

◆ init()

void SynthLab::AudioBuffer::init ( uint32_t  _numInputChannels,
uint32_t  _numOutputChannels,
uint32_t  _blockSize 
)

Main initializer that creates the new arrays and sets up the object.

setup the buffers for a set number of channels - this cannot change after init

Parameters
_numInputChannelsinput channel count (1 = mono, 2 = stereo, may be greater than 2 if needed)
_numOutputChannelsinput channel count (1 = mono, 2 = stereo, may be greater than 2 if needed)
_blockSizethe MAXIMUM block size that sets the buffer sizes; this can never be exceeded

◆ setSamplesInBlock()

void SynthLab::AudioBuffer::setSamplesInBlock ( uint32_t  _samplesInBlock)

Set the number of samples in a block for processing.

  • only used because the block size COULD be variable if the host DAW or plugin framework supplies an input or output buffer that is a partial block size; very rare, but still possible
Parameters
_samplesInBlocknumner of samples in block

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