TracktionEngine
Loading...
Searching...
No Matches
graph::AudioBufferPool Class Reference

A lock-free pool of audio buffers. More...

#include <tracktion_AudioBufferPool.h>

Public Member Functions

 AudioBufferPool ()=default
 Create an empty pool.
 AudioBufferPool (size_t maxCapacity)
 Creates pool with a given max capacity.
choc::buffer::ChannelArrayBuffer< float > allocate (choc::buffer::Size)
 Returns an allocated buffer for a given size from the pool.
bool release (choc::buffer::ChannelArrayBuffer< float > &&)
 Releases an allocated buffer back to the pool.
void reset ()
 Releases all the internal allocated storage.
void setCapacity (size_t)
 Sets the maximum number of buffers this can store.
size_t getCapacity () const
 Returns the current maximum number of buffers this can store.
void reserve (size_t numBuffers, choc::buffer::Size)
 Reserves a number of buffers of a given size, preallocating them.
size_t getNumBuffers ()
 Returns the current number of buffers in the pool.
size_t getAllocatedSize ()
 Returns the currently allocated size of all the buffers in bytes.

Detailed Description

A lock-free pool of audio buffers.

If you need to quickly create and then return some audio buffers this class enables you to do that in a lock free way.

Note that the buffers can be pre-allocated but if you ask for a buffer which isn't in the pool, it will either resize an existing one or allocate a new one.

After processing a constant audio graph for a while though this should be completely allocation and lock-free.

Constructor & Destructor Documentation

◆ AudioBufferPool() [1/2]

graph::AudioBufferPool::AudioBufferPool ( )
default

Create an empty pool.

You won't be able to use this pool right away, you must set a capacity and reserve some a number of buffers for it to use first.

See also
setCapacity, reserve

Referenced by AudioBufferPool().

◆ AudioBufferPool() [2/2]

graph::AudioBufferPool::AudioBufferPool ( size_t maxCapacity)

Creates pool with a given max capacity.

See also
reserve

References AudioBufferPool(), and setCapacity().

Member Function Documentation

◆ allocate()

choc::buffer::ChannelArrayBuffer< float > graph::AudioBufferPool::allocate ( choc::buffer::Size size)

Returns an allocated buffer for a given size from the pool.

This will attempt to get a buffer from the pre-allocated pool that can fit the size but if one can't easily be found, it will allocate one with new and return it.

Additionally, the returned buffer may be bigger than the size asked for so be sure to only use a view of it but retain ownership of the whole buffer. You can release it back to the pool later. It will also contain junk so be sure to clear or initialise the view required before use.

See also
release

[[ thread_safe ]]

References allocate().

Referenced by allocate().

◆ release()

bool graph::AudioBufferPool::release ( choc::buffer::ChannelArrayBuffer< float > && buffer)

Releases an allocated buffer back to the pool.

Returns
true if the buffer was able to fit in the pool, false if it couldn't and had to be deallocated in place

[[ thread_safe ]]

References release().

Referenced by release().

◆ reset()

void graph::AudioBufferPool::reset ( )

Releases all the internal allocated storage.

References setCapacity().

◆ setCapacity()

void graph::AudioBufferPool::setCapacity ( size_t maxCapacity)

Sets the maximum number of buffers this can store.

References setCapacity().

Referenced by AudioBufferPool(), reset(), and setCapacity().

◆ getCapacity()

size_t graph::AudioBufferPool::getCapacity ( ) const

Returns the current maximum number of buffers this can store.

◆ reserve()

void graph::AudioBufferPool::reserve ( size_t numBuffers,
choc::buffer::Size size )

Reserves a number of buffers of a given size, preallocating them.

References reserve().

Referenced by reserve(), and graph::node_player_utils::reserveAudioBufferPool().

◆ getNumBuffers()

size_t graph::AudioBufferPool::getNumBuffers ( )

Returns the current number of buffers in the pool.

N.B. This isn't safe to call concurrently with any other methods.

References getNumBuffers().

Referenced by getNumBuffers().

◆ getAllocatedSize()

size_t graph::AudioBufferPool::getAllocatedSize ( )

Returns the currently allocated size of all the buffers in bytes.

N.B. This isn't safe to call concurrently with any other methods as it needs to pop and then push all the elements to examine their size.

References getAllocatedSize().

Referenced by getAllocatedSize().


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