|
tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications
« « « Anklang Documentation |
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. | |
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.
|
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.
| tracktion::graph::AudioBufferPool::AudioBufferPool | ( | size_t | maxCapacity | ) |
Creates pool with a given max capacity.
Definition at line 113 of file tracktion_AudioBufferPool.h.
| 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.
[[ thread_safe ]]
Definition at line 118 of file tracktion_AudioBufferPool.h.
| 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.
| 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.
| 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.
| bool tracktion::graph::AudioBufferPool::release | ( | choc::buffer::ChannelArrayBuffer< float > && | buffer | ) |
Releases an allocated buffer back to the pool.
[[ thread_safe ]]
Definition at line 139 of file tracktion_AudioBufferPool.h.
| 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.
| 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.