TracktionEngine
Public Member Functions | List of all members
tracktion::graph::AudioBufferStack Class Reference

A stack of audio buffers. More...

Public Member Functions

 AudioBufferStack ()=default
 Create an empty stack. More...
 
choc::buffer::ChannelArrayBuffer< float > allocate (choc::buffer::Size)
 Returns an allocated buffer for a given size from the stack. More...
 
void release (choc::buffer::ChannelArrayBuffer< float > &&)
 Releases an allocated buffer back to the stack. More...
 
void reset ()
 Releases all the internal allocated storage. More...
 
void reserve (size_t numBuffers, choc::buffer::Size)
 Reserves a number of buffers of a given size, preallocating them. More...
 
size_t getNumBuffers ()
 Returns the current number of buffers in the stack. More...
 
size_t getAllocatedSize ()
 Returns the currently allocated size of all the buffers in bytes. More...
 

Detailed Description

A stack of audio buffers.

If you need to quickly create and then return some audio buffers this class enables you to do that.

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.

However, it is not thread safe so you should use a different stack for each thread!

Constructor & Destructor Documentation

◆ AudioBufferStack()

tracktion::graph::AudioBufferStack::AudioBufferStack ( )
default

Create an empty stack.

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

See also
reserve

Member Function Documentation

◆ allocate()

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

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

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

◆ release()

void tracktion::graph::AudioBufferStack::release ( choc::buffer::ChannelArrayBuffer< float > &&  buffer)

Releases an allocated buffer back to the stack.

◆ reset()

void tracktion::graph::AudioBufferStack::reset ( )

Releases all the internal allocated storage.

◆ reserve()

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

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

◆ getNumBuffers()

size_t tracktion::graph::AudioBufferStack::getNumBuffers ( )

Returns the current number of buffers in the stack.

◆ getAllocatedSize()

size_t tracktion::graph::AudioBufferStack::getAllocatedSize ( )

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


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