tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
Public Member Functions | List of all members
tracktion::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< floatallocate (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.

Definition at line 33 of file tracktion_AudioBufferPool.h.

Constructor & Destructor Documentation

◆ AudioBufferPool() [1/2]

tracktion::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

◆ AudioBufferPool() [2/2]

tracktion::graph::AudioBufferPool::AudioBufferPool ( size_t  maxCapacity)

Creates pool with a given max capacity.

See also
reserve

Definition at line 113 of file tracktion_AudioBufferPool.h.

Member Function Documentation

◆ allocate()

choc::buffer::ChannelArrayBuffer< float > tracktion::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 ]]

Definition at line 118 of file tracktion_AudioBufferPool.h.

◆ getAllocatedSize()

size_t tracktion::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.

Definition at line 227 of file tracktion_AudioBufferPool.h.

◆ getCapacity()

size_t tracktion::graph::AudioBufferPool::getCapacity ( ) const

Returns the current maximum number of buffers this can store.

Definition at line 80 of file tracktion_AudioBufferPool.h.

◆ getNumBuffers()

size_t tracktion::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.

Definition at line 200 of file tracktion_AudioBufferPool.h.

◆ release()

bool tracktion::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 ]]

Definition at line 139 of file tracktion_AudioBufferPool.h.

◆ reserve()

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

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

Definition at line 156 of file tracktion_AudioBufferPool.h.

◆ setCapacity()

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

Sets the maximum number of buffers this can store.

Definition at line 145 of file tracktion_AudioBufferPool.h.


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