AudioBufferPool

class AudioBufferPool(poolSize: Int, bufferSize: Int)

Pre-allocated buffer pool for zero-allocation audio processing.

This pool provides reusable FloatArray buffers for real-time DSP operations, avoiding garbage collection pauses in the hot path.

Usage

val pool = AudioBufferPool(poolSize = 4, bufferSize = 2048)

// Acquire a buffer for processing
val buffer = pool.acquire()

// Fill with audio samples
audioBuffer.fillFloatSamples(buffer)

// Process with Calibra
calibra.detectPitch(buffer, sampleCount)

// Release back to pool
pool.release(buffer)

Thread Safety

All operations are thread-safe. Multiple threads can acquire and release buffers concurrently.

Parameters

poolSize

Number of buffers to pre-allocate

bufferSize

Size of each buffer in samples

Constructors

Link copied to clipboard
constructor(poolSize: Int, bufferSize: Int)

Properties

Link copied to clipboard

Number of buffers currently available in the pool.

Link copied to clipboard

Total buffers created (includes overflow allocations). If this exceeds poolSize, the pool was exhausted at some point.

Link copied to clipboard

Check if the pool has been exhausted (more allocations than poolSize). Use this in debug builds to tune poolSize.

Functions

Link copied to clipboard

Acquire a buffer from the pool.

Link copied to clipboard
fun release(buffer: FloatArray)

Release a buffer back to the pool.

Link copied to clipboard

Reset pool statistics (for debugging).